Are there any restrictions on ObjectPath in ASSOCI

2019-07-27 18:04发布

问题:

Let's take for example the following request:

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

It works fine and returns the corresponding list with (in my case) one logical disk, F:. However if I change the method of specifying the object in this query, for example, this way:

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

I get the "Invalid object path" error (in PowerShell). The field DiskIndex is definitely there (the request "SELECT * FROM Win32_DiskPartition WHERE DiskIndex=2" returns the one and only partition that resides on my disk #2), so what's wrong with such request? I also tried using some other fields of Win32_DiskPartition class, but none of them worked in the "ASSOCIATORS OF" request. Anywhere in the Internet (that is, where google sent me) there is no information about any restrictions on the ObjectPath. Moreover, I found one article where the author explicitly says:

This qualifier can be any property from the source WMI class

So, what's wrong with this request modification?

回答1:

The ObjectPath is a string that uniquely identifies a instance of a class, and is conformed by the key property of the WMI Class, so you cannot use any property to build a ObjectPath. in this case the Object Path of the Win32_DiskPartition uses the DeviceID property which is the Key property for this class.

The basic syntax for the ASSOCIATORS OF is

ASSOCIATORS OF {ObjectPath}

So you only can pass a valid object pass to this sentence.



标签: wmi