PowerShell for Windows Admins

Apr 24 2018   1:09PM GMT

CIM references and associations

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


Way back in 2011, when I were just a young lad, I wrote about WMI or CIM references and associations – https://wordpress.com/read/blogs/16267735/posts/1673

ASSOCIATORS show the end point of the link between CIM classes and REFERENCES shows the linking class.

I used the Win32_NetworkAdapter class in the example because it has a known association with Win32_NetworkAdapterConfiguration.

One thing I appear to have not made clear is that you have to use the key to the CIM class in the query for the reference or association. The key for a Win32_networkadapter class is DeviceID.

This became clear when a reader pointed out that this won’t work:

PS> Get-WmiObject -Query “REFERENCES OF {win32_printer.name = ‘fax’}”
Get-WmiObject : Invalid object path
At line:1 char:1
+ Get-WmiObject -Query “REFERENCES OF {win32_printer.name = ‘fax’}”
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

But that

Get-WmiObject -Query “REFERENCES OF {Win32_Printer.DeviceID=’Fax’}”

works. Again DeviceId is the key to the class.

Usually its better to go straight to the association and bypass the reference.

A better approach than writing WQL queries is to use the CIM cmdlets

$p = Get-CimInstance -ClassName Win32_Printer -Filter “Name=’Fax'”

Get-CimAssociatedInstance -InputObject $p

will show you the data from the associated classes.

If you just want to see the associated class names

PS> Get-CimAssociatedInstance -InputObject $p | select CIMclass


And if you just want the data for a particular associated class

PS> Get-CimAssociatedInstance -InputObject $p -ResultClassName Win32_PrinterDriver

Caption                 :
Description             :
InstallDate             :
Name                    : Microsoft Shared Fax Driver,3,Windows x64
Status                  :
CreationClassName       : Win32_PrinterDriver
Started                 :
StartMode               :
SystemCreationClassName : Win32_ComputerSystem
SystemName              :
ConfigFile              : C:\WINDOWS\system32\spool\DRIVERS\x64\3\FXSUI.DLL
DataFile                : C:\WINDOWS\system32\spool\DRIVERS\x64\3\FXSUI.DLL
DefaultDataType         :
DependentFiles          : {C:\WINDOWS\system32\spool\DRIVERS\x64\3\FXSWZRD.DLL,
DriverPath              : C:\WINDOWS\system32\spool\DRIVERS\x64\3\FXSDRV.DLL
FilePath                :
HelpFile                :
InfName                 :
MonitorName             :
OEMUrl                  :
SupportedPlatform       : Windows x64
Version                 : 3
PSComputerName          :

 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: