Parsing WMI results

(imported topic written by Harald.Zarakowitis)

Hi,

I need help with this relevance.

I copied a query from the forum which lists all AD-groups which the client is member of.

string values of selects (
"DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & 
"'")  of wmi 
"root\directory\ldap"

Now I want to query, if the client is member of a specific group. That is what I used:

exists selects (
"DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & 
"'") whose (string value of it contains 
"VIE") of wmi 
"root\directory\ldap"

However, this does not work. It always displays ‘false’. It seems that it does not iterate over the list.

What´s interesting is, that the following relevance

string values of selects (
"DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & 
"'") whose (string value 1 of it contains 
"VIE") of wmi 
"root\directory\ldap"

has as output

CN=VIEPR-G020Z315-1,OU=Printers,OU=vie,OU=at,DC=company,DC=com CN=VIEPR-G020Z315-2,OU=Printers,OU=vie,OU=at,DC=company,DC=com CN=VIEPR-G020Z328-1,OU=Printers,OU=vie,OU=at,DC=company,DC=com     Evaluates to plural object of type string

(imported comment written by BenKus)

Hi Harald,

The “exists” in the second clause should return True if there are any results. There is a “string value 1 of…” in your third clause. Is that a typo?

Can you double check to make sure that you have the appropriate syntax and you have a computer and using QnA, you can establish:

  • The computer returns results from a query.
  • Adding an “exists” to the front of this query returns false.

If so, that is sort of shocking to me because I fully don’t expect that piece to fail… Let me know what you find…

Ben

(imported comment written by Harald.Zarakowitis)

Ben,

“string value 1” is not a fault.

For instance:

string values of selects (
"DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & 
"'") whose (string value 0 of it contains 
"315") of wmi 
"root\directory\ldap"

has the same output as:

string values of selects (
"DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & 
"'") whose (string value 2 of it contains 
"328") of wmi 
"root\directory\ldap"

which is

CN=VIEPR-G020Z315-1,OU=Printers,OU=vie,OU=at,DC=company,DC=com CN=VIEPR-G020Z315-2,OU=Printers,OU=vie,OU=at,DC=company,DC=com CN=VIEPR-G020Z328-1,OU=Printers,OU=vie,OU=at,DC=company,DC=com     Evaluates to plural object of type string

Note that string value 0 contains a number “315” and string value 2 contains “328”. If I ask if string value 2 contains “315” the query result is

Evaluates to plural object of type string

So no result, but also no error.

exists selects (
"DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & 
"'") whose (string value 0 of it contains 
"315") of wmi 
"root\directory\ldap"

returns TRUE. Asking for the string “328” returns FALSE. This is correct, but the problem is, that I don´t know the string value of the group I look. I think its very weird behaviour, since I think I got the syntax right.

The only way I can think of now is to put together 5-8 of these lines with “OR” operators.

I hope I´ve done something wrong and it is really an easy solution.

Harald

(imported comment written by jessewk)

Hi Harald,

I still am not sure the desired output you are looking for, but I think you have a small issue with the placement of the ‘whose’ clause that might explain your issues.

Look at these 2 queries:

  1. string values of selects (…) whose (…) of wmi …
  2. string values whose (…) of selects (…) of wmi …

Query number 1 will always return ALL string values for the select, as long as one of the string values matches the filter in the whose clause.

Query number 2 will only return string values that match the filter in the whose clause.

Please let us know if that works for you. If it doesn’t, please post the desired final result for an example query.

-Jesse

(imported comment written by Harald.Zarakowitis)

Jesse,

I don´t get it :wink:

My desired output would be simply ‘true’ or ‘false’ when I ask a client if it is a member of a AD specific group.

At the moment I use this relevance (which is not very professional I have to admit):

(exists selects ("DS_MemberOf from DS_Computer where DS_Name='" & (computer name) & "'") whose ((string value 0 of it contains "AD-Group") OR (string value 1 of it contains "AD-Group") OR (string value 2 of it contains "AD-Group") OR (string value 3 of it contains "AD-Group") OR (string value 4 of it contains "AD-Group") OR (string value 5 of it contains "AD-Group") OR (string value 6 of it contains "AD-Group") OR (string value 7 of it contains "AD-Group") OR (string value 8 of it contains "AD-Group") OR (string value 9 of it contains "AD-Group") OR (string value 10 of it contains "AD-Group")) of wmi "root\directory\ldap")

(imported comment written by jessewk)

Does this work for you?

(
exists string values
whose
(
it contains “AD-Group”
)
of selects
(
“DS_MemberOf from DS_Computer where DS_Name=’” & computer name & “’”
)
of wmi “root\directory\ldap”
)

(imported comment written by kwdobbin)

I am looking for a way to determine if a computer is a member of a domain security group. What is the correct WMI query to accomplish this?