Where Clause

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Where Clause

Post by new_user »

[script attached]. I have a small script that adds and removes Domain groups from the Local Admin group. This script is part of a GPO and runs when users log on to their machines. I am not sure where to use this, but I want this script to only run on Windows XP or Windows 2000 Professional machines, essentially not %server%.
Because this is differnet than some newer type scripts in that I am not using collections or running against an OU, I do not know first the exact syntx nor where to enter the syntax in so this does not run against machines with %server% on them.
(where objOperatingSystem.Caption =)

Thanks in advance for the help.


'This script will loop the through the Local Admin group and add / remove members as defined in the'adGrp.Add and oGrp.Remove variable.
On Error Resume Next
'get main objects/variablesSet ws = WScript.CreateObject ( "WScript.Shell" )compname = ws.ExpandEnvironmentStrings ( "%COMPUTERNAME%" )'Add GroupsSet adGrp = GetObject ( "WinNT://" & compname & "/Administrators,group" )'Remove groupsSet oGrp = GetObject("WinNT://" & compname & "/Administrators,group")
'Add Domain Global Groups to Local Admin groupadGrp.Add ( "WinNT://domain1/Admins,group" )adGrp.Add ( "WinNT://domain2/Admins,group" )
'Remove Global Groups from Local Admin groupoGrp.Remove("WinNT://domain/Old_Group,group")new_user2007-06-06 11:03:06
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Where Clause

Post by new_user »

[script attached]. I have a small script that adds and removes Domain groups from the Local Admin group. This script is part of a GPO and runs when users log on to their machines. I am not sure where to use this, but I want this script to only run on Windows XP or Windows 2000 Professional machines, essentially not %server%.
Because this is differnet than some newer type scripts in that I am not using collections or running against an OU, I do not know first the exact syntx nor where to enter the syntax in so this does not run against machines with %server% on them.
(where objOperatingSystem.Caption =)

Thanks in advance for the help.


'This script will loop the through the Local Admin group and add / remove members as defined in the'adGrp.Add and oGrp.Remove variable.
On Error Resume Next
'get main objects/variablesSet ws = WScript.CreateObject ( "WScript.Shell" )compname = ws.ExpandEnvironmentStrings ( "%COMPUTERNAME%" )'Add GroupsSet adGrp = GetObject ( "WinNT://" & compname & "/Administrators,group" )'Remove groupsSet oGrp = GetObject("WinNT://" & compname & "/Administrators,group")
'Add Domain Global Groups to Local Admin groupadGrp.Add ( "WinNT://domain1/Admins,group" )adGrp.Add ( "WinNT://domain2/Admins,group" )
'Remove Global Groups from Local Admin groupoGrp.Remove("WinNT://domain/Old_Group,group")new_user2007-06-06 11:03:06
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Where Clause

Post by jvierra »

You cannot do this from a GPO except if it is an admin loggong on. Users cannot normally alter teh contents of groups.

If you want a script to run only on certain types of machines you can do this using a Group Policy Filter.

If machines are separated into OUs that reflect their roles then you could just apply it at the OU level. If machines are mixed use the GP filter.

If machines are in the "default" COmputers container then you will not be able to isolate a GPO. This is one of the major reasons for moving computers to OUs that track their roles.

Look into using a GP with "Restricted Groups Policy" as this is the recommended method.

(where objOperatingSystem.Caption =)

is a piece of a WMI query. I am not sure what you are trying to do with this piece of code.



User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Where Clause

Post by new_user »

jvierra thanks. This script is currently in a GPO, the scripts runs when a user logs on to a machine, the users in my environment are Local Admins so the script does run. What I am trying to accomplisg within the script is, I want to add code to it so when the script starts it looks at the OS of the machine, if the OS is not %professional% do not run the script [or if it is %professional%, run].
Seperating my machines into different OU's is not a option for my environment, and a GPO filter will not work on a Windows 2000 Version X machine, only XP or 2003+.

So I am just looking to see if I can get this script to look at the OperatingSystem caption if if its %server%, do not run.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Where Clause

Post by jvierra »

You can't match %server% with a WMI query. You have to get teh caption and use "InStr" to see if the string is in teh caption.

User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Where Clause

Post by new_user »

Sorry it was an example. So how would I do that or what would the code be?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Where Clause

Post by jvierra »

This will get you started.

Set wmi = GetObject("winmgmts://./root/cimv2") Set col = wmi.ExecQuery("select * from Win32_OperatingSystem") For Each os In col MsgBox os.Caption Next
This topic is 16 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked