-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added script to add users or groups to local groups on a machine conn…
…ected to Active Directory
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
On Error Resume Next | ||
'================================================================================ | ||
' * Adds users or groups from a domain to a workstation's local groups * | ||
' | ||
'Example usage | ||
'addLocalToLocal "LocalGroup","Administrators" | ||
'addToLocal "DomainGroup","Administrators","DOMAINNAME" | ||
'================================================================================ | ||
'Clean up objects | ||
Set oGroup = nothing | ||
Set oWshNet = nothing | ||
Set oUser = nothing | ||
WScript.Quit | ||
' | ||
' Add domain users or groups to local groups | ||
' | ||
Sub addToLocal(netUser,lGroup,Domain) | ||
sDomain = Domain | ||
sUser = netUser | ||
Set oUser = GetObject("WinNT://" & sDomain & "/" & sUser) | ||
Set oWshNet = CreateObject("Wscript.Network") | ||
sComputerName = oWshNet.ComputerName | ||
'checkForErr | ||
sGroup = lGroup | ||
Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroup) | ||
'checkForErr | ||
oGroup.add(oUser.ADsPath) | ||
End Sub | ||
' | ||
' Add local accounts to local groups | ||
' | ||
Sub addLocalToLocal(netUser,lGroup) | ||
Set oWshNet = CreateObject("Wscript.Network") | ||
sComputerName = oWshNet.ComputerName | ||
'checkForErr | ||
sUser = netUser | ||
Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser) | ||
sGroup = lGroup | ||
Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroup) | ||
'checkForErr | ||
oGroup.add(oUser.ADsPath) | ||
End Sub | ||
' | ||
' Check if an error has occured | ||
' | ||
Sub checkForErr | ||
If err.number <> 0 Then | ||
Wscript.Echo("An error has occured." & Err.Number) | ||
WScript.Quit | ||
End If | ||
End Sub | ||
'=============================================================================== |