Skip to content

Instantly share code, notes, and snippets.

@johnddias
Created February 9, 2014 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnddias/8901848 to your computer and use it in GitHub Desktop.
Save johnddias/8901848 to your computer and use it in GitHub Desktop.
vCAC Automate Local Admin permissions with AD Security Group
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