PowerShell 3.0 introduces a new family of NetAdapter of cmdlets. Get-NetAdapter is the default, and its job is to enumerate your computer’s network cards (NICs).
Tutorial for Get-NetAdapter
- The Magic of PowerShell’s NetAdapter
- Simple Example of Get-NetAdapter
- Research NetAdapter Properties
- How to Enable or Disabled Your NIC
- Research The NetAdapter Cmdlet Family
To appreciate the elegance of Get-NetAdapter, you have to experienced the uglyness of enumerating network cards using NetSh or VBScript; even with PowerShell 2.0’s Get-WmiObject Win32_NetworkAdapterConfiguration it wasn’t easy to list NICs.
One aspect of elegance that I admire, especially in scripting, is simplicity. Therefore to get started all you need is the command: Get-NetAdapter.
# PowerShell 3.0 lists all your computer’s network cards.
Note 1: You can find more properties by piping the output into | Get-Member.
Important: Adjust the value of my $Nic variable depending on the results of the simple: Get-NetAdapter command.
$Nic = "Wi-Fi"
Get-NetAdapter -name $Nic | Format-List Name,`
InterfaceDescription, DeviceName, DeviceWakeupEnable,`
LinkSpeed, NetworkAddress, PromiscuousMode, Status
Note 2: Take care with the ` backtick; in particular avoid spaces after this command that tells PowerShell to word-wrap to the next line.
Note 3: Here is an even better plan, research your own properties with:
Get-NetAdapter | Get-Member
SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
Understanding Get-NetAdapter’s Parameters
Employing the -name parameter is a precise method for specifying the network card, and it saves me having to use Powershell’s Where-Object statement to filter the network cards.
Let us call for Get-Help and see which other parameters are available for the Get-NetAdapter cmdlet.
#PowerShell NetAdapter parameter research
Results: I found two interesting parameters -IncludeHidden and -physical.
Once you have discovered a useful PowerShell cmdlet such as Get-NetAdapter it’s worth investigating alternative verbs; this is how I discovered Enable, Disable and Restart-NetAdapter.
Get-Command -Noun netadapter
CommandType Name ModuleName
———– —— ————
Function Disable-NetAdapter NetAdapter
Function Enable-NetAdapter NetAdapter
Function Get-NetAdapter NetAdapter
Function Rename-NetAdapter NetAdapter
Function Restart-NetAdapter NetAdapter
Function Set-NetAdapter NetAdapter
Here is an example to disable the Wi-Fi’s network adapter.
# PowerShell script to disable your network card.
$Nic = ‘Wi-Fi’
Disable-NetAdapter -Name $Nic
Note 4: To reverse the action substitute Enable-NetAdapter for Disable-Network adapter.
Note 5: See more on PowerShell’s Disable-NetAdapter.
PowerShell’s default verb is ‘Get’. Thus, my challenge is to substitute plain NetAdapter for Get-NetAdapter in the above examples. Actually, I regard this shortcut as sloppy scripting, but it does explain why other PowerShell commands work the way they do, for example:
… is really ‘Get-Help’ Disable-NetAdapter, but as ‘Get’ is the default verb, the shorter form works.
This freeware monitor is great for checking whether your network’s load-balancing is performing as expected, for example, are two interfaces are getting about equal traffic?
It’s easy to install and straightforward to configure. You will soon be running tests to see how much network bandwidth your applications consume.
The GUI has a lovely balance between immediate network traffic data in the middle, combined with buttons to seek related data and configuration settings. Give this monitor a try, it’s free!
If you need more comprehensive network analysis software:
Download a free trial of NPM (Network Performance Monitor)
- Launch PowerShell (Preferably the ISE version)
- Copy the lines of code in the above examples (into memory).
- Right-click in the top pane.
More PowerShell v 3.0 Networking Cmdlets
One way to discover more about the new version 3 cmdlets is to look at the ‘Modules’ section of PowerShell ISE’s Commands pane.
Summary of PowerShell Get-NetAdapter
PowerShell 3.0 introduces a new family of NetAdapter cmdlets which manipulate a computer’s NICs. This page shows you how to research the properties of your network card(s).
If you like this page then please share it with your friends
See more Microsoft PowerShell v 3.0 examples