WMI Collection or Instance?
I was working with WMI in PowerShell today trying to get some disk data from a cluster, and I ran into an odd behavior that had me stumped for a while. Here’s a simplified version of the problem (this is not what I was doing with the cluster, but the WMI behavior is identical). I got a WMI object with the intent of using an associator class to get related information. In this example, I get a Win32_LogicalDisk instance and try to relate it to Win32_DiskPartition. I used the following commands:PS C:\> $z=gwmi win32_logicaldisk -filter "DeviceID='C:'"
PS C:\> $y=$z.psbase.GetRelated("Win32_DiskPartition")
PS C:\> $y.name
PS C:\>PS C:\> $y
NumberOfBlocks : 75504448
BootPartition : True
Name : Disk #0, Partition #0
PrimaryPartition : True
Size : 38658277376
Index : 0PS C:\> $y.gettype().FullName
System.Management.ManagementObjectCollectionPS C:> $($y).name
Disk #0, Partition #0PS C:\> $y=$($z.psbase.GetRelated("Win32_DiskPartition"))
PS C:\> $y.name
Disk #0, Partition #0
No comments:
Post a Comment