WMI Class Win32_NetworkAdapter
Win32_NetworkAdapter is one of 7 Windows Management Instrumentation (WMI) classes that provides access to your network card. PowerShell can not only provide command-line access to the settings, but also show properties such as NetConnectionStatus which are not visible in the Control Panel, or to IpConfig.
Topics for PowerShell and Win32_NetworkAdapter
- PowerShell Command to Display Network Adapter Values
- How to Research Properties for YOUR Computer Configuration
- PowerShell Script To Test Which Network Connections are Active
- Filter the Output for ‘Real’ Network Cards
- How to Enable or Disable NIC in PowerShell 3.0
♣
PowerShell Tutorial to List WMI Classes
Pre-requisites: Visit Microsoft’s site and download the correct version of PowerShell for your operating system.
- Launch PowerShell (Preferably the ISE version)
- Copy the lines of code below (into memory)
- Right-click on the PowerShell symbol
- Edit –> Paste
- Press enter to execute the code.
PowerShell Command to Display Network Adapter Values
While you could interrogate Win32_NetworkAdapter with VBScript, it is much easier and quicker to manipulate WMI classes with PowerShell. A reminder that the master cmdlet is Get-WmiObject, indeed it’s worth researching parameters and examples with Get-Help Get-WmiObject.
# Simple PowerShell script to display properties of your NICs.
# Author: Guy Thomas
# Version 3.2 February 2010 tested on PowerShell v 1.0 and 2.0
Get-WmiObject -Class Win32_NetworkAdapter
Sample Result
ServiceName : yukonw7
MACAddress : 00:1F:C6:E3:25:85
AdapterType : Ethernet 802.3
DeviceID : 7
Name : Marvell Yukon 88E8052 PCI-E ASF Gigabit Ethernet Controller
NetworkAddresses :
Speed : 100000000
Note 1: As usual, you can view all a PowerShell cmdlets parameters with Get-Help, for example:
Get-Help Get-WmiObject.
Note 2: You could use the alias PowerShell gwmi instead of Get-WmiObject
Guy Recommends: Free WMI Monitor for PowerShell
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.
Download your free copy of WMI Monitor
How to Research Properties for YOUR Computer Configuration
I could tell you which properties to script, but it’s much better if you learn how to view the master list, then make selections to suit your particular needs or project.
# Script to research properties of Win32_NetworkAdapter
# Author: Guy Thomas
# Version 2.2 February 2010 tested on PowerShell v 1.0 and 2.0
Get-WmiObject Win32_NetworkAdapter | Get-Member
Note 3: Above is a one-line command. Below is a refinement to filter the properties that you are likely to be interested in.
Note 4: A reminder that even this command accepts Get-Help, thus you could try:
Get-Help Get-Member -full. My point is that help will reveal other options, for example -MemberType Method.
# Script to research properties of Win32_NetworkAdapter
# Author: Guy Thomas
# Version 2.5 February 2010 tested on PowerShell v 1.0 and 2.0
Get-WmiObject Win32_NetworkAdapter | Get-Member
-MemberType Property [a-z]*
Note 5: Try substituting -MemberType Method for -MemberType Property
Note 6: Below is an edited example of the output.
AdapterType
AdapterTypeId
DeviceID
InterfaceIndex
MACAddress
Manufacturer
MaxSpeed
Name
NetConnectionID
NetConnectionStatus
NetEnabled
NetworkAddresses
PhysicalAdapter
ServiceName
Speed
Status
StatusInfo
Try SolarWinds Free Wake-on-LAN Gadget »
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)
More Example Scripts for WMI Win32_NetworkAdapter
PowerShell Script To Test Which Network Connections are Active
# PowerShell script to check NetConnectionStatus of your active NICs
# Author: Guy Thomas
# Version 1.5 February 2010 tested on PowerShell v 1.0 and 2.0
Clear-Host
Get-WmiObject -Class Win32_NetworkAdapter | `
Format-Table Name, NetEnabled, NetConnectionStatus, DeviceId -auto
Note 7: The key property is NetEnabled. In the output we are looking for values of ‘True’. For your information the NetConnectionStatus of active NICs will be 2 and not 7.
Note 8: PowerShell has no word-wrap, thus we use the backtick ` to tell the command to continue on the next line.
Trap: With the backtick there should be no space after the `.
Note 9: Observe PowerShell’s trademark the (|) pipe symbol, this means that the output of the main command is pumped into Format-Table. I chose, NetEnabled, NetConnectionStatus, DeviceId from the dozens of possible Win32_NetworkAdapter properties of to display.
See also PowerShell 3.0 Get-NetIPConfiguration »
Filter the Output for ‘Real’ Network Cards
This example also employs -computerName LocalHost, which you could change to the name, or IP address of a machine on your network.
# PowerShell script to list your ‘Real’ network cards.
# Author: Guy Thomas
## Version 1.5 February 2010 tested on PowerShell v 1.0 and 2.0
Clear-Host
Get-WmiObject -Class win32_networkadapter -computerName LocalHost `
-filter "NetConnectionStatus = 2" | `
Format-Table Name, NetEnabled, NetConnectionStatus, DeviceId -auto
Note 10: The filtering is achieved through this clause:
-filter "NetConnectionStatus = 2" Actually, you could substitute a ‘Where’ clause thus:
Where-Object {$_.NetConnectionStatus -eq ‘2’}
Note 11: PowerShell has no word-wrap, thus the backtick ` means continue on the next line. Beware, there should be no space after the `.
Challenge: Change -computerName LocalHost to the value of a machine on your network.
Next Step: To discover the IP address try the sister class Win32_NetworkAdapterConfiguration
Real-life Task – How To Disable a Network Card with PowerShell
Preliminaries – Vital for Success. Decide which machine you are configuring, this script is set for LocalHost. Important: Your DeviceId is unlikely to be 17, so please research and amend for your computer.
# Script using Win32_Networkadapter to disable a NIC.
# Author: Guy Thomas
## Version 2.3 February 2010 tested on PowerShell v 1.0 and 2.0
Clear-host
$Nic = Get-WmiObject win32_networkadapter -computerName LocalHost `
-filter "DeviceId = 17"
$Nic.disable()
Note 12: If the script did not work, then change DeviceId =17. Also check which machine you wish to disable. -ComputerName ???
Note 13: To reverse the script the command is $Nic.enable().
Note 14: I recommend you run this script in conjunction with the above script.
SolarWinds Firewall Browser
Here is an utility where you can review firewall settings such as access control lists (ACL), or troubleshoot problems with network address translation (NAT).
Other reasons to download this SolarWinds Firewall Browser include managing requests to change your firewall settings, testing firewall rules before you go live, and querying settings with the browser’s powerful search options.
Guy recommends that you download a copy of the SolarWinds free Firewall Browser.
How to List More WMI Network Classes
The additional feature of this script is that refines the search from the broad ‘Win32’, to the narrower ‘Win32_Network’. The result is a list of network WMI classes.
# PowerShell example to list every WMI class matching Win32_network
# Author: Guy Thomas
# Version 1.5 February 2010 tested on PowerShell v 1.0 and 2.0
Clear-Host
$i=0
$Type = "Win32_network"
$WMI = Get-WmiObject -List | Where-Object {$_.name -Match $Type}
Foreach ($Class in $WMI) {$Class.name; $i++}
Write-Host ‘There are’ $i’ types of ‘$Type
Learning Points
Note 15: In practical terms, most of the 7 network classes are disappointing. However, the class Win32_NetworkAdapterConfiguration has the useful property of DefaultIPGateway and IpAddress.
Summary of WMI Win32_NetworkAdapter Class
The key point is that PowerShell’s Get-WmiObject needs is a WMI class. These Win32_NetworkAdapter examples will help you to research properties for your task such as NetConnectionStatus. For pure PowerShell research remember this combination: Get-Help and Get-Member.
If you like this page then please share it with your friends
See More Microsoft PowerShell WMI Examples:
• Home • PowerShell Get-WmiObject • Windows PowerShell • PowerShell 3.0 Network
• Win32_pingstatus • WMI Win32_NetworkAdapter • Win32_NetworkAdapterConfig
• Disable NIC • PowerShell -Filter • PowerShell -Query • PowerShell Select • Free WMI Monitor
Please email me if you have any example scripts. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.