Script to add username to local admin
Hi,
Has anyone a vbscript that prompts for username, then adds the username to Local Administrator Group?
Thanks.
Has anyone a vbscript that prompts for username, then adds the username to Local Administrator Group?
Thanks.
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
gmorgan618
16 years ago
Feel free to edit this code as you see fit... Repost questions, i'll answer them when i check back.
To add a user(instead of a group) you'll have to change the objGroup declaration in the For loop to ",user" instead of ",group" - If the User acct is a local account not a domain then the DomainName is the ObjGroup.add line should be set to ".".
You can rename the strADGroupName to strUserNames(or arrUserNames if you're picky about variable representation) and use an Inputbox to prompt the user for their SUI then populate this variable.
Hope this makes sense, it's fairly easy stuff - or as Joe Dirt calls it "Day one stuff" -- :)
btw - Admin access by the executor needed in order to perform the group add.
'Begin Code
'Hide errors
Dim SUPPRESS_ERRORS : SUPPRESS_ERRORS = True
'Domain Name
Dim DomainName : DomainName = "Test.org"
'Active Directory Group Name information
Dim strADGroupName : strADGroupName = "Domain Admins"
'CSV can be used to list multiple groups
'Dim strADGroupName : strADGroupName = "Domain Admins, Users, Everyone"
'Local Group that AD Group should be added to
Dim strAddToGroup : strAddToGroup = "Administrators"
'==========================================================================
'Calling Main SubRountine
Main()
'==========================================================================
Sub Main()
If SUPPRESS_ERRORS Then On Error Resume Next
Dim ComputerName : ComputerName = "."
ComputerName = Trim(ComputerName)
DomainName = Trim(DomainName)
strAddToGroup = Trim(strAddToGroup)
Dim arrADGroups : arrADGroups = split(strADGroupName, ",")
For Each strCurrentGroup In arrADGroups
strCurrentGroup = Trim(strCurrentGroup)
Dim objGroup : Set objGroup = GetObject("WinNT://" & ComputerName & "/" & strAddToGroup & ",group")
objGroup.Add "WinNT://" & DomainName & "/" & strCurrentGroup
'If Err.Number = "-2147023518" Then MsgBox("Account membership already exists")
Next
End Sub
'End Code
To add a user(instead of a group) you'll have to change the objGroup declaration in the For loop to ",user" instead of ",group" - If the User acct is a local account not a domain then the DomainName is the ObjGroup.add line should be set to ".".
You can rename the strADGroupName to strUserNames(or arrUserNames if you're picky about variable representation) and use an Inputbox to prompt the user for their SUI then populate this variable.
Hope this makes sense, it's fairly easy stuff - or as Joe Dirt calls it "Day one stuff" -- :)
btw - Admin access by the executor needed in order to perform the group add.
'Begin Code
'Hide errors
Dim SUPPRESS_ERRORS : SUPPRESS_ERRORS = True
'Domain Name
Dim DomainName : DomainName = "Test.org"
'Active Directory Group Name information
Dim strADGroupName : strADGroupName = "Domain Admins"
'CSV can be used to list multiple groups
'Dim strADGroupName : strADGroupName = "Domain Admins, Users, Everyone"
'Local Group that AD Group should be added to
Dim strAddToGroup : strAddToGroup = "Administrators"
'==========================================================================
'Calling Main SubRountine
Main()
'==========================================================================
Sub Main()
If SUPPRESS_ERRORS Then On Error Resume Next
Dim ComputerName : ComputerName = "."
ComputerName = Trim(ComputerName)
DomainName = Trim(DomainName)
strAddToGroup = Trim(strAddToGroup)
Dim arrADGroups : arrADGroups = split(strADGroupName, ",")
For Each strCurrentGroup In arrADGroups
strCurrentGroup = Trim(strCurrentGroup)
Dim objGroup : Set objGroup = GetObject("WinNT://" & ComputerName & "/" & strAddToGroup & ",group")
objGroup.Add "WinNT://" & DomainName & "/" & strCurrentGroup
'If Err.Number = "-2147023518" Then MsgBox("Account membership already exists")
Next
End Sub
'End Code
Posted by:
Meic
16 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.