Discussion:
How to specify current computername in WMI filter
(too old to reply)
RMP
2007-05-17 17:31:01 UTC
Permalink
I want to apply a user-based GPO based on computer group membership using a
WMI filter. I have a WMI query to check for group membership except I cannot
determine how to specify a variable for the current computername to put in
the query. What I need is a way to substitute 'CurrentComputername$' with
something like '%computername%$' in the following WMI filter. This obviously
easy enough to do in a normal vbscript, but I don't know if it is possible to
environment variables or any kind of variable in a GPO WMI filter

Select * FROM Win32_GroupUser WHERE GroupComponent =
"Win32_Group.Domain='MyDomain',Name='MyComputerGroup'" And PartComponent =
"Win32_UserAccount.Domain='MyDomain',Name='CurrentComputername$'"
Mark Heitbrink [MVP]
2007-05-17 18:11:09 UTC
Permalink
Hi,
[...] What I need is a way to substitute 'CurrentComputername$' with
something like '%computername%$' in the following WMI filter. [...]
From my understanding, you can not use %computername%, you need to
use the STRING value of it, otherwise the WMI query wouldn´t make any
sense, it would always be true ...

e.g.:
SELECT * FROM Win32_ComputerSystem WHERE Name = 'MyComputer'
is only efectiv on "MyComputer", that´s a filter.

SELECT * FROM Win32_ComputerSystem WHERE Name = '%computername%'
this is not a filter, this is applied to everyone, because
%computername% is always true.

Mark
--
Mark Heitbrink - MVP Windows Server - Group Policy

Homepage: www.gruppenrichtlinien.de - deutsch
Blog: gpupdate.spaces.live.com - english
RMP
2007-05-17 19:48:04 UTC
Permalink
I know I cannot use %computername% as it would actually evaluate false, but I
cannot hard code a computername as it would always evaluate true or false
depending on whether that computer is actually a member of the said group.

If it is not possible to pass in the computername is there any other way to
evaluate whether a computer is member of group via a WMI filter?
Post by Mark Heitbrink [MVP]
Hi,
[...] What I need is a way to substitute 'CurrentComputername$' with
something like '%computername%$' in the following WMI filter. [...]
From my understanding, you can not use %computername%, you need to
use the STRING value of it, otherwise the WMI query wouldn´t make any
sense, it would always be true ...
SELECT * FROM Win32_ComputerSystem WHERE Name = 'MyComputer'
is only efectiv on "MyComputer", that´s a filter.
SELECT * FROM Win32_ComputerSystem WHERE Name = '%computername%'
this is not a filter, this is applied to everyone, because
%computername% is always true.
Mark
--
Mark Heitbrink - MVP Windows Server - Group Policy
Homepage: www.gruppenrichtlinien.de - deutsch
Blog: gpupdate.spaces.live.com - english
Loading...