Are there any restrictions on ObjectPath in an ASSOCIATORS OF statement?

Take for example the following query:

ASSOCIATORS OF {Win32_DiskPartition.DeviceID="Disk #2, Partition #0"} WHERE AssocClass = Win32_LogicalDiskToPartition 

It works fine and returns a matching list with (in my case) a single logical drive, F :. However, if I change the method of specifying an object in this query, for example, as follows:

 ASSOCIATORS OF {Win32_DiskPartition.DiskIndex=2} WHERE AssocClass = Win32_LogicalDiskToPartition 

I get an "Invalid Object Path" error (in PowerShell). The DiskIndex field certainly exists (the query "SELECT * FROM Win32_DiskPartition WHERE DiskIndex = 2" returns the one and only partition that is on my disk number 2), so what happened to this request? I also tried using some other classes of the Win32_DiskPartition class, but none of them worked in the "ASSOCIATORS OF" query. There is no information about any restrictions on ObjectPath anywhere on the Internet (that is, where Google sent me). Moreover, I found an article where the author clearly says:

This classifier can be any property from the source WMI class.

So what is wrong with this request modification?

+1
source share
1 answer

ObjectPath is a string that uniquely identifies an instance of a class and matches the key property of the WMI class, so you cannot use any property to build ObjectPath . in this case, the Win32_DiskPartition object Win32_DiskPartition uses the DeviceID property, which is the Key property for this class.

enter image description here

The basic syntax of ASSOCIATORS OF is

 ASSOCIATORS OF {ObjectPath} 

Thus, you can pass the actual pass of the object to this offer.

+3
source

Source: https://habr.com/ru/post/1486597/


All Articles