List Your Network Adapters with PowerShell 3.0
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
♣
The Magic of PowerShell’s NetAdapter
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.
Simple Example of Get-NetAdapter
# PowerShell 3.0 lists all your computer’s network cards.
Get-NetAdapter
Note 1: You can find more properties by piping the output into | Get-Member.
Research NetAdapter Properties
Important: Adjust the value of my $Nic variable depending on the results of the simple: Get-NetAdapter command.
Clear-Host
$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
Guy Recommends: A Free Trial of the Network Performance Monitor (NPM) v11.5
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.
Download a free trial of Solarwinds’ Network Performance Monitor
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
Clear-Host
Get-Help Get-NetAdapter
Results: I found two interesting parameters -IncludeHidden and -physical.
Research Microsoft’s NetAdapter Cmdlet Family
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
How to Enable or Disabled Your NIC
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.
NetAdapter Challenge
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:
Help Disable-NetAdapter
… is really ‘Get-Help’ Disable-NetAdapter, but as ‘Get’ is the default verb, the shorter form works.
Guy Recommends: SolarWinds Free Network Bandwidth Monitor
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!
Download your free network bandwidth monitor
If you need more comprehensive network analysis software:
Download a free trial of NPM (Network Performance Monitor)
Getting Started With PowerShell v 3.0
- Launch PowerShell (Preferably the ISE version)
- Copy the lines of code in the above examples (into memory).
- Right-click in the top pane.
- Paste.
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.
See more examples of PowerShell v 3.0 NetAdapter cmdlets »
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
• PowerShell 3.0 • What’s New in PowerShell 3.0 • PowerShell v 3.0 ISE • PowerShell Home
• Get-NetAdapter • Disable-NetAdapter • Enable-NetAdapter • Get-NetIPConfiguration
• PowerShell Network Cmdlets • PowerShell 3.0 Logon Script • PowerShell Show-Command