SOLVED: No easy way to combine multiple WMI properties of multiple WMI instances

There is no easy way to iterate over a set of WMI instances and use multiple properties together per instance. Ideally the results from the query would be grouped so that they could be accessed in a per-instance basis more easily.

WMI results are given as a plural set of strings across all instances, which makes it hard to match up multiple properties with the instance they belong to.

Here are some examples: ( in this case I have 2 monitors that happened to have been made at the same time, but that is a coincidence )

q:selects "InstanceName,WeekOfManufacture,YearOfManufacture from WMIMonitorID" of wmis "root\wmi"
A: InstanceName=DISPLAY\MONITOR1
A: WeekOfManufacture=45
A: YearOfManufacture=2012
A: InstanceName=DISPLAY\MONITOR2
A: WeekOfManufacture=45
A: YearOfManufacture=2012
T: 6.461 ms
I: plural wmi select

I have to combine it all into a single string, break it apart using the first item returned, normalize the strings, and then parse them:

q:((date "01 Jan 0000") + (item 0 of it as integer)*year + (item 1 of it as integer)*week, it) of (following text of last ";YearOfManufacture=" of preceding text of last ";" of it, preceding text of first ";" of following text of last ";WeekOfManufacture=" of it,it) of (if (it ends with ";") then it else it & ";") of (it as trimmed string) whose(it != "") of substrings separated by "InstanceName=" of concatenations ";" of (it as string) whose(it contains "=") of selects "InstanceName,WeekOfManufacture,YearOfManufacture from WMIMonitorID" of wmis "root\wmi"
A: ( Sun, 11 Nov 2012 ), ( 2012, 45, DISPLAY\MONITOR1;WeekOfManufacture=45;YearOfManufacture=2012; )
A: ( Sun, 11 Nov 2012 ), ( 2012, 45, DISPLAY\MONITOR2;WeekOfManufacture=45;YearOfManufacture=2012; )
T: 5.946 ms
I: plural ( date, ( substring, substring, string ) )

References:

https://support.bigfix.com/inspectors/Primitive%20Objects_Any.html#date

To get each instance returned separately, you want to use select objects, rather than select. Using selects just flattens the returned data as a list, which is normally fine when getting the properties of a single object.

(As I don’t have multiple monitors, I used memory device to show the plural return values.)

Q: (String value of Properties "Description" of it,String value of Properties"DeviceID" of it,String value of Properties"StartingAddress" of it)  of select objects "* from win32_MemoryDevice" of wmi

A: Memory Device, Memory Device 0, 0
A: Memory Device, Memory Device 1, 4194304
T: 3.874 ms
I: plural ( string, string, string )

So, you either want just the returned values for your properties:

Q: (String value of Properties "InstanceName" of it,String value of Properties"WeekOfManufacture" of it,String value of Properties"YearOfManufacture" of it) of select objects "InstanceName,WeekOfManufacture,YearOfManufacture from WMIMonitorID" of wmis "root\wmi"

A: DISPLAY\ACI27E3\5&1d2a693b&0&UID1048848_0, 34, 2012
T: 4.701 ms
I: plural ( string, string, string )

Or if you want to keep the field names intact (to possibly extract and use later), just return the Name=Value of each one:

Q: (Properties "InstanceName" of it,Properties "WeekOfManufacture" of it,Properties "YearOfManufacture" of it) of select objects "InstanceName,WeekOfManufacture,YearOfManufacture from WMIMonitorID" of wmis "root\wmi"

A: InstanceName=DISPLAY\ACI27E3\5&1d2a693b&0&UID1048848_0, WeekOfManufacture=34, YearOfManufacture=2012
T: 4.932 ms
I: plural ( wmi select, wmi select, wmi select )

3 Likes

I’ll have to play around with it, but I do think that solves my issue. I have used “select objects” before, but I never quite figured out how it was different.

Thanks. That does do what I was looking for.

Here are some example relevance I have written with select objects based upon this concept:

http://bigfix.me/relevance/details/3002172
http://bigfix.me/relevance/details/3002173
http://bigfix.me/relevance/details/3002174