PowerShell for Windows Admins

Sep 6 2010   12:47PM GMT

WMI and Network Adapters: 4



Posted by: Richard Siddaway
Network, PowerShell v2

We have looked at using Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration. 

Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetEnabled=’$true’" |
Format-List NetConnectionID, Description, MACAddress, Speed

Get-WmiObject -Class Win32_NetworkAdapterConfiguration |
where {$_.IPAddress} | Foreach { $_.Description; $_ |
select -ExpandProperty IPAddress}

Now we need to look at combining the information from the two classes. One way to do it is like this

001
002
003
004
005
006
007
008
009
010
011
012
Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetEnabled=’$true’" | 
foreach {
 $_ | Format-List NetConnectionID, Description, MACAddress, Speed 

 $filt = "Index=’" + $_.DeviceID + "’"
 $nic = `
 Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter $filt 
 
 $nic | Format-List DefaultIPGateway, IPSubnet, DNSServerSearchOrder
 "IP Address"
 $nic | select -ExpandProperty IPAddress
}

This doesn’t give the most elegant of results so we will need to refine what we are doing

Comment on this Post

Leave a comment: