WMI linked classes

You will find that many WMI classes have links – some are associations built in to WMI (a subject for another time) while other classes can be linked based on property values. An example of the latter is the Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration classes. The DeviceId on Win32_NetworkAdapter  matches Index on Win32_NetworkAdapterConfiguration .

The follwoing function (adapted from a question on the forum) shows one way this link can be used

function Get-NetworkInfo{
    param( [string]$ComputerName )

    $networkinfo = @()

    $networks = Get-WmiObject Win32_Networkadapter -Filter ‘NetEnabled=True’ -ComputerName $ComputerName
    $adapter = 0
    foreach($network in $networks){

        $id = $network.DeviceId
        $IPinfo = Get-WmiObject win32_networkadapterconfiguration -Filter “Index = $id” -ComputerName $ComputerName
        $winServers = 0
        $winServers = ($IPinfo.WinsPrimaryServer -join ‘,’),($IPinfo.WinsSecondaryServer -join ‘,’)

        $adapter += 1

        $props = @{
            ‘Adapter’ = $adapter;
            ‘Manufacturer’ = $network.Manufacturer;
            ‘Description’ = $network.Description;
            ‘Connection’ = $network.NetConnectionID;
            ‘SpeedGB’ = [math]::Round($network.Speed / 1GB, 2)
            ‘IPAddress’ = $IPinfo.IPAddress -join ‘,’
            ‘Submask’ = $IPinfo.IPSubnet -join ‘,’
            ‘Gateway’ = $IPinfo.DefaultIPGateway -join ‘,’
            ‘DNSServers’ = $IPinfo.DnsServerSearchOrder-join ‘,’
            ‘WinServers’ = $winServers -join ‘,’
            ‘DomainSuffixes’ = $IPinfo.DNSDomainSuffixSearchOrder -join ‘,’
        $networkinfo += New-Object -TypeName psobject -Property $props
Get-NetworkInfo -ComputerName $env:COMPUTERNAME

This entry was posted in CIM, PowerShell and WMI. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s