0
votes

I need help on a WMI query for a Group Policy WMI-Filter. I'm querying the win32_group namespace within the root\CIMV2 WMI provider.

I am doing a search for a Local Security group (like "Administrators") on several window's computer (XP-8, server 03-12). When the query runs on a computer I would like it to inject the computer name into the equivalency field for the Domain.

The base WQL statement looks like this:

SELECT * FROM win32_group 
WHERE Domain="currentComputerName" and Name="Administrators"

My goal is to run a WQL statement along these lines, but it is a bad WQL statement:

SELECT * FROM win32_group 
WHERE Domain=(SELECT Name FROM Win32_ComputerSystem) and Name="Administrators" 

It is important that I am able to inject the current computer's name for the Domain. These computers are part of a Active Directory (AD) domain. By default the win32_group will search all of the AD Domain's groups in addition to the Local Computer's security group (if omitting the Domain parameter). By specifying the local machine name as the domain the query's performance is multitudes faster - which is essential for its purpose.

I have tried some query variations in WBEMTEST with no luck. Does anybody have any ideas on how to inject the computer's name into the WQL WMI Query? Is there possibly a constant that I could use, like HOSTNAME at the command prompt?

Thank you for your help!

1

1 Answers

0
votes

What language are you writing this in? Or to be clear, what programming or scripting language you are using to run these WMI queries?

In PowerShell, you could do this by running the following code:

Get-WMIObject -Query "SELECT * FROM Win32_Group WHERE Domain='$env:USERDOMAIN' AND Name='Administrators'"