PowerShell WMI

Guy recommends:
Free config generator

Solarwinds Config Generator

This CG will put you in charge of controlling changes to network routers and other SNMP devices.

Download your free Config Generator



WMI Class Win32_NetworkAdapterConfiguration

WMI Class 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 and Win32_NetworkAdapterConfiguration

 ♣

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 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:  You could use the alias PowerShell gwmi instead of get-WmiObject

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_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 1: Above is a one-line command.  Below is a refinement to filter the properties that you are likely to be interested in.

Note 2:  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_NetworkAdapterConfiguration
# Author: Guy Thomas
# Version 2.5 February 2010 tested on PowerShell v 1.0 and 2.0

get-WmiObject Win32_NetworkAdapterConfiguration | get-Member `
-MemberType Property | where-Object{$_.name -notMatch "__"}

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

Note 2: Instead of a where clause you simplify to: -MemberType Property [a-z]*

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

Guy Recommends: WMI Monitor and Its Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.  Fortunately, Solarwinds have created the WMI Monitor so that you can examine these gems of performance information for free.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

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 1:  PowerShell has no word-wrap, thus the backtick ` means continue on the next line.  Beware, there should be no space after the `.

Note 2: 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 1:  You could replace Where-Object {$_.IPEnabled -eq 'True'} with a -filter parameter.  Check the syntax with get-Help get-WmiObject -full.

Note 2:  PowerShell has no word-wrap, thus the backtick ` means continue on the next line.  Beware, there should be no space after the `.

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 1:  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'.

Guy Recommends: WMI Monitor and Its Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.  Fortunately, Solarwinds have created the WMI Monitor so that you can examine these gems of performance information for free.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Summary of WMI Class Win32_NetworkAdapterConfiguration

The key information that PowerShell's get-WmiObject needs is a WMI class.  These Win32_NetworkAdapterConfiguration examples will help you to research the best properties for your task.  For pure PowerShell research remember get-Help and get-Member.

See More Microsoft PowerShell WMI Examples:

Home   • PowerShell WMI   • WMI Services   • Memory   • Disk   • DNS   • Win32_pingstatus

WMI Class   • Win32_NetworkAdapter   • Win32_NetworkAdapterConfiguration   • Disable NIC

Examples   • Win32_product   • PowerShell -Query   • PowerShell -Filter

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2010 Computer Performance LTD All rights reserved

Please report a broken link, or an error.