Skip to content

Commit

Permalink
added script to add users or groups to local groups on a machine conn…
Browse files Browse the repository at this point in the history
…ected to Active Directory
  • Loading branch information
cosmin committed Oct 31, 2007
1 parent 1b2204d commit 26d5f83
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions bitsandpieces/addtolocalgroups/addtolocal.vbs
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
'===============================================================================

0 comments on commit 26d5f83

Please sign in to comment.