VBscript to Add all Users of a OU to a Group
VBscript to Add all Users of a OU to a Group PDF Print E-mail
Written by Administrator   
Monday, 02 November 2009 11:25

I have written a script to add all users of an OU to a group, there are many reason why one would want to do such a thing, I will give you my example.

I have created a security group that controls Internet access, now I wish to add departments to this group. Unfortunately you can not just add the OU "Accounts" or "Finance" to your new security group you will need to add the users through a script.

In the example below I have taken all users from the OU "ouName" and added them to the Group "groupName"

Copy text below to notepad, and save as "OU2Group.vbs"

'**********************************************************************
' OU2Group.vbs
'
' Author......: Gary Smith, TheAwkward.Net
'
' Date Written: 2/11/2009
'
' Usage: Cscript OU2Group.vbs
'
' Notes:
' Change the LDAP to match your own domain name
'
'**********************************************************************
On Error Resume Next
Set objOU = GetObject("LDAP://OU=ouName, dc=The-Awkward, dc=net")
Set objGroup = GetObject("LDAP://CN=groupName, CN=Users, dc=The-Awkward, dc=net")

For Each objUser in objOU
    strUser=objuser.AdsPath
    objGroup.Add strUser
    WScript.Echo "Added " & strUser
Next

'**********************************************************************

 

Last Updated ( Monday, 02 November 2009 13:00 )
 
Joomla Templates by Joomlashack