GetRelated() from System.Management equivalent in Microsoft.Management.Infrastructure namespace

36 views Asked by At

In the System.Management namespace there is a GetRelated() method, as shown here.

This gets the associators of a given ManagementObject. Presumably, this functions similarly to the Get-CimAssociatedInstances powershell cmdlet for interacting with WMI objects.

I am attempting to implement an equivalent in the Microsoft.Management.Infrastructure namespace, which is what Microsoft recommends as the new API for interacting with WMI in managed code.

I have tried to implement a solution using a WQL query with ASSOCIATORS OF clause. This required me to implement a path generator as the __Path and __Relpath properties are not populated in the new API (this might be a bug). However, in doing so, I realized that not all CimInstance objects actually have valid WMI paths, which renders this approach useless.

For example, the CimInstance of type 'Msvm_ComputerSystem' returned by DefineSystem in the Hyper-V WMI Provider (v2) has all KEY properties as null, which results in a non-existent ObjectPath, therefore querying with ASSOCIATORS OF is impossible.

I am looking for a way to query the associators without a valid WMI ObjectPath using the Microsoft.Management.Infrastructure namespace or some other WQL query.

0

There are 0 answers