Combining Network Adapter Information

by Jul 29, 2011

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!