Combining Network Adapter Information

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

In a previous tip you learned that WMI network adapter information is separated into two classes. Win32_NetworkAdapter represents the hardware, and Win32_NetworkAdapterConfiguration contains the configuration details. To mix information from both classes, take a look at this:

Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' | 
  ForEach-Object {
    $info = $_ | Select-Object *
    
    $nic = $_.GetRelated('Win32_NetworkAdapter')
    $nic | 
      Get-Member -MemberType *property | 
      ForEach-Object { if ($_.Name.StartsWith('__') -eq $false) {
        Add-Member -In $info NoteProperty $_.Name $nic.$($_.Name) -ea 0
      }
     }
     $info
    }

The code gets all network adapters with an IP address assignment, then use GetRelated() to find the related hardware information from Win32_NetworkAdapter. At the end, the hardware information is merged into the configuration information so you get a new rich object which combines all network adapter information.

 

Twitter This Tip! ReTweet this Tip!


Posted Jul 29 2011, 06:00 AM by ps1

Comments

jbruns2010 wrote re: Combining Network Adapter Information
on 07-29-2011 10:30 AM

Would be nice to see adapter speed and duplex settings.  Since this is vendor dependent and from what I found, only in the registry, it would be challenging.

RSiddaway wrote re: Combining Network Adapter Information
on 07-29-2011 2:13 PM

we can also use a WQL query to get the related information.

see

msmvps.com/.../powershell-deep-dive-v-wmi-associations.aspx

RSiddaway wrote re: Combining Network Adapter Information
on 07-29-2011 4:05 PM

If you want the duplex setting see this post

msmvps.com/.../network-adapter-speed-and-duplex.aspx

Copyright 2012 PowerShell.com. All rights reserved.