PowerShell Win32_NetworkAdapterConfiguration

PowerShell Win32_NetworkAdapterConfiguration

Windows Management Instrumentation (WMI) provides a way of accessing details of your operating system that are normally hidden from the Control Panel, Device manager or IpConfig.  While there are 7 WMI classes dealing with network properties, the most versatile is: WMI Class Win32_NetworkAdapterConfiguration.

Topics for PowerShell Win32_NetworkAdapterConfiguration

 ♣

PowerShell Command to Display Network Adapter Values

While you could employ VBScript to interrogate Win32_NetworkAdapterConfiguration, PowerShell is much easier and quicker to learn.  A reminder that the master cmdlet is Get-WmiObject, indeed it’s worth researching parameters and examples with Get-Help Get-WmiObject.

# PowerShell script to display network properties.
# Author: Guy Thomas
# Version 2.2 February 2010 tested on PowerShell v 1.0 and 2.0

Get-WmiObject -Class Win32_NetworkAdapterConfiguration

Sample Result

DHCPEnabled : False
IPAddress : {192.168.1.10}
DefaultIPGateway : {192.168.1.254}
DNSDomain :
ServiceName : yukonw2
Description : Marvell Yukon 88E8052 PCI-E ASF Gigabit Ethernet Controller
Index : 2

Note 1: As usual, you can view all a PowerShell cmdlets parameters with Get-Help, for example:
Get-Help Get-WmiObject.

Note 2: Many script writers use PowerShell's alias gwmi instead of Get-WmiObject.

See also PowerShell 3.0 Get-NetIPConfiguration »

Guy Recommends: SolarWinds Free Wake-On-LAN UtilitySolarwinds Wake-On-LAN

Encouraging computers to sleep when they’re not in use is a great idea – until you are away from your desk and need a file on that remote sleeping machine!

WOL also has business uses for example, rousing machines so that they can have update patches applied.  My real reason for recommending you download this free tool is because it’s so much fun sending those ‘Magic Packets’. Give WOL a try – it’s free.

Download your free copy of SolarWinds Wake-On-LAN

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 yourself, then make selections to suit your particular needs or project.

# Script to research properties of Win32_NetworkAdapterConfiguration
# Author: Guy Thomas
# Version 2.2 February 2010 tested on PowerShell v 1.0 and 2.0
Get-WmiObject Win32_NetworkAdapterConfiguration | 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.

Note 5: See my review of Solarwinds Wake-On-Lan utility.

# Script to research properties of Win32_NetworkAdapterConfiguration
# Author: Guy Thomas
# February 2010 tested on PowerShell v 1.0 and 2.0
Clear-Host
Get-WmiObject Win32_NetworkAdapterConfiguration |
Get-Member -MemberType Property | Where-Object {$_.name -NotMatch "__"}

Note 6: Below is an edited example of the output.

Note 7: Instead of that 'Where-Object' clause you simplify to:
Get-Member -MemberType Property [a-z]*

Name 
—- ———- 
DefaultIPGateway
DefaultTOS
DefaultTTL 
Description
DHCPEnabled 
DHCPLeaseExpires 
DHCPLeaseObtained 
DHCPServer
DNSDomain 
GatewayCostMetric
InterfaceIndex
IPAddress
MACAddress 

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds 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

More Example Scripts for Win32_NetworkAdapterConfiguration

Example to test if you are using DHCP

# PowerShell script to list your computer’s IP address(es)
# Author: Guy Thomas
# Version 1.5 February 2010 tested on PowerShell v 1.0 and 2.0

Clear-Host
Get-WmiObject Win32_NetworkAdapterConfiguration | Format-Table `
IPAddress, DHCPEnabled, DefaultIPGateway, Description -autosize

Note 8: PowerShell has no word-wrap, thus the backtick ` means continue on the next line.  Beware, 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.  Now we can decide which or the dozens of possible properties to display.

Example which filters for ‘real’ IP addresses.  It also displays the default gateway and the MAC address.

# PowerShell script to list your computer's IP address(es)
# Author: Guy Thomas
# Version 1.5 February 2010 tested on PowerShell v 1.0 and 2.0
Clear-Host
Get-WmiObject -class Win32_NetworkAdapterConfiguration |
Where-Object {$_.IPEnabled -eq 'True'} |
Format-Table IPAddress, DefaultIPGateway, MACAddress -auto

Note 10: You could replace Where-Object {$_.IPEnabled -eq ‘True’} with a -filter parameter.  Check the syntax with Get-Help Get-WmiObject -full.  See also PowerShell and Ipconfig.

Note 11: You could also employ a 'Where' clause to display only network adapters with IP Addresses: Where-Object {$_.IpAddress -ne $Null} |

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 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

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 12:  In practical terms, most of the 7 network classes are disappointing.  However, the class win32_networkadapter has the useful property of NetConnectionStatus, and also the handy methods: ‘Enable’ and Disable’.

Summary of WMI Class Win32_NetworkAdapterConfiguration

The key information that PowerShell's Get-WmiObject needs is a WMI class.  The Win32_NetworkAdapterConfiguration examples on this page will help you to research the best properties for your task.  For pure PowerShell research remember 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.