PowerShell for Windows Admins

May 1 2011   4:13AM GMT

PowerShell Deep Dive: V WMI associations

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


NOTE: If you are wondering why the Deep Dive posts are non-consecutive – they are part of a longer series posted here http://msmvps.com/blogs/richardsiddaway/default.aspx

WMI classes will sometimes have be associated with other classes for example each instance of the Win32_NetworkAdatper class is associated with an instance of the Win32_NetworkAdapterConfiguration.  The link is expressed by the Win32_NetworkAdapterSetting which shows the links.

I normally use WQL queries based on ASSOCIATORS and REFERENCES to discover these classes.  ASSOCIATORS shows the end point of the link and REFERENCES shows the linking class

We can do some of this work directly from the WMI object.

Lets get a network adapter object (you will need to use a deviceid thats present on your machine)

$nic = Get-WmiObject Win32_NetworkAdapter  -Filter “DeviceId=11”

and check its methods

$nic | gm -MemberType method

This doesn’t show what we need so we’ll drop to the underlying object

$nic.psbase | gm -MemberType method

which shows two methods of interest


We could also use

$nic | gm -MemberType method -View base

The methods relate to WQL like this

GetRelated = Associations
GetRelationships = References

What we get with these methods is the full related object.  We don’t have a method on the object to discover the classes that are related. For that we stick with WQL

Get-WmiObject -Query “ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=11} WHERE ClassDefsOnly”
Get-WmiObject -Query “REFERENCES OF {Win32_NetworkAdapter.DeviceID=11} WHERE ClassDefsOnly”

though these snippets are equivalent

$nic.GetRelated() | select __class –Unique

$nic.GetRelationships() | select __class –Unique

If we want to see the associated classes we can do this



Get-WmiObject -Query “ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=11}”

For a specific result class we can do this



et-WmiObject -Query “ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=11} WHERE ResultClass=Win32_NetworkAdapterConfiguration”

Switching to the links between classes – if we want to see all the links



Get-WmiObject -Query “REFERENCES OF {Win32_NetworkAdapter.DeviceID=11} ”

and if we want to see a single link



Get-WmiObject -Query “REFERENCES OF {Win32_NetworkAdapter.DeviceID=11} WHERE ResultClass=Win32_NetworkAdapterSetting”

This gives us two routes to the information we need.  Use whichever you are most comfortable with.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: