Has anyone a vbscript that prompts for username, then adds the username to Local Administrator Group?

0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


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
'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

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")

End Sub
'End Code
Answered 12/05/2007 by: gmorgan618
Blue Belt

Please log in to comment
Hi gmorgan - thanks very much for taking time to reply - I modified it and it worked - cheers! [;)]
Answered 12/06/2007 by: Meic
Second Degree Blue Belt

Please log in to comment