/build/static/layout/Breadcrumb_cap_w.png

Help with script to add group to local admins...

I need some help resolving an issue I get when trying to modify the following script to add a domain group to the local admins group. Here's the error I'm getting after making a few modifications:

Script: C:\AddLAdmin.vbs
Line: 8
Char: 17
Error: Syntax error
Code: 800A03EA
Source: Microsoft VBScript compilation error

Here's the script I'm using:

------------------------------------------------------------------------------------------
Option Explicit

Dim WshShell , strLocalGroup, strMachineName, strDomainGroup, strDomainName

Set WshShell = CreateObject ("Wscript.Shell")

strLocalGroup = <Administrators> <-- I added Administrators >
strMachineName = <machine-name-here or .>
strDomainGroup = <SecAdmins> <-- This is the name of my group >
strDomainName = <MyDomain> <-- This is the name of my domain>

ChangeLocalGroup strLocalGroup, "ADD", strMachineName, strDomainGroup, strDomainName

'ChangeLocalGroup strLocalGroup, "REMOVE", strMachineName, strDomainGroup, strDomainName

'------------------------------------------------------------------------------------------

Sub ChangeLocalGroup (strLocalGroup, strActionType, strComputerName, strDomainGroup, strDomainName)

Dim objLocalGroup, objDomainGroup

on error resume next

'Look up local group.
Set objLocalGroup = GetObject("WinNT://" & strComputerName & "/" & strLocalGroup & ",group")

If err.number <> 0 Then
WriteLog "Failed to lookup local " & strLocalGroup & " group in " & strComputerName & _
" - error: " & err.number
Err.Clear
Exit Sub
End If

' Look up Domain group to be checked against local group.
Set objDomainGroup = GetObject( "WinNT://" & strDomainName & "/" & strDomainGroup & ",group")

If err.number <> 0 Then
WriteLog "Failed to lookup " & strDomainGroup & " in " & strDomainName & " - error: " & err.number
Err.Clear
Exit Sub
End If

select case ucase(strActionType)
case "REMOVE"
'Check if domain group already a member.
If objLocalGroup.IsMember(objDomainGroup.AdsPath) Then
'Remove domain group from local group.
objLocalGroup.Remove(objDomainGroup.AdsPath)
If err.number <> 0 Then
WriteLog "Failed to remove " & strDomainGroup & " from local " & strLocalGroup & " group - error: " & err.number
Err.Clear
Else
WriteLog "Removed " & strDomainGroup & " from local " & strLocalGroup & " group."
End If
End If

case "ADD"
'Check if domain group already a member.
If not objLocalGroup.IsMember(objDomainGroup.AdsPath) Then
'Add domain group to local group.
objLocalGroup.Add(objDomainGroup.AdsPath)
If err.number <> 0 Then
WriteLog "Failed to add " & strDomainGroup & " to local " & strLocalGroup & " group - error: " & err.number
Err.Clear
Else
WriteLog "Added " & strDomainGroup & " to local " & strLocalGroup & " group."
End If
End If
end select

End Sub 'ChangeLocalGroup

'------------------------------------------------------------------------------------------

Sub WriteLog (strMessage)

WshShell.LogEvent 0,strMessage

End Sub 'WriteLog

'------------------------------------------------------------------------------------------

I'm sure I'm missing something simple therefore any responses are appreciated.

0 Comments   [ + ] Show comments

Answers (1)

Posted by: WiseUser 18 years ago
Fourth Degree Brown Belt
0
It works perfectly as it is. All I changed were the following lines:

strLocalGroup = "Administrators"
strMachineName = "."
strDomainGroup = "Domain Users"
strDomainName = "MyDomain"

Obviously, "MyDomain" needs to be replaced with your own domain name.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ