/build/static/layout/Breadcrumb_cap_w.png

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.

0 Comments   [ + ] Show comments

Answers (2)

Posted by: gmorgan618 16 years ago
Blue Belt
0
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
Posted by: Meic 16 years ago
Second Degree Blue Belt
0
Hi gmorgan - thanks very much for taking time to reply - I modified it and it worked - cheers! [;)]
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