Created
February 9, 2014 16:43
-
-
Save johnddias/8901848 to your computer and use it in GitHub Desktop.
vCAC Automate Local Admin permissions with AD Security Group
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 | |
Dim groupSuffix | |
groupSuffix = WScript.Arguments(1) | |
adGroupName = computerName & groupSuffix | |
logFile.WriteLine "Domain " & userDomain & " extracted." | |
logFile.WriteLine "Adding AD Group " & adGroupName & " to local administrators..." | |
Set objGroup = GetObject("WinNT://" & computerName & "/Administrators,group") | |
Set objUser = GetObject("WinNT://" & userDomain & "/" & adGroupName & ",group") | |
If Not ObjGroup.IsMember(objUser.ADsPath) Then | |
objGroup.Add(objUser.ADsPath) | |
logFile.WriteLine "User " & adGroupName & " added to local administrators group." | |
Else | |
logFile.WriteLine "User " & adGroupname & " already member of local administrators, nothing done." | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment