Last active
August 29, 2015 13:56
-
-
Save johnddias/8829865 to your computer and use it in GitHub Desktop.
Add User To Local Admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim objFSO, logFile | |
Set objFSO = CreateObject("Scripting.FileSystemObject") | |
Set logFile = objFSO.OpenTextFile("C:\scripts\addgroup.log", 2, True) | |
Set objWshNet = CreateObject("WScript.Network") | |
computerName= objWshNet.ComputerName | |
logFile.WriteLine "Computer Name: " & computerName | |
Dim fullUpn | |
fullUpn = WScript.Arguments(0) | |
Dim userName | |
Dim userDomain | |
Dim clipped | |
If InStr(fullUpn,"@") Then | |
clipped = Split(fullUpn,"@") | |
userName = clipped(0) | |
userDomain = clipped(1) | |
Elseif InStr (fullUpn,"\") Then | |
clipped = Split(fullUpn,"\") | |
userName = clipped(1) | |
userDomain = clipped(0) | |
End If | |
logFile.WriteLine "User name " & userName & " extracted." | |
logFile.WriteLine "Adding to local administrators..." | |
Set objGroup = GetObject("WinNT://" & computerName & "/Administrators,group") | |
Set objUser = GetObject("WinNT://" & userDomain & "/" & userName & ",user") | |
If Not ObjGroup.IsMember(objUser.ADsPath) Then | |
objGroup.Add(objUser.ADsPath) | |
logFile.WriteLine "User " & userName & " added to local administrators group." | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment