VB Script required to create bulk users in a AD group

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Iam looking for VBScript for either of the following use cases.

A VB Script that would add buk users in a group unders "Users" in AD(There is no OU created under Users. Only a group is created) .
Ive created some bulk users with some prefix (ex:test is the prefix where test1,test2,test3 etc are the user accounts) in AD "Users" without creating any OU or group. Now I created a group manually in Users and would like to add all the user accounts with
test prefix to that group.
Found some script on the web and tried modified as follows for the second case but it is not working
Option Explicit <br/>
Dim objRootLDAP, objGroup, objUser, objOU<br/>
Dim strOU, strGroup, strDNSDomain<br/>
Dim intCounter
Check these objects referenced by strOU, strGroup exist in strOU<br/>
strOU = "CN=Users,"<br/>
strGroup = "CN=Group1,"
Bind to Active Directory and get LDAP name<br/>
Set objRootLDAP = GetObject(" LDAP://RootDSE ")<br/>
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
Prepare the OU and the Group<br/>
Set objGroup = GetObject("LDAP://"& strGroup _<br/>
& strOU & strDNSDomain)<br/>
Set objOU =GetObject("LDAP://" & strOU & strDNSDomain)
On Error Resume next<br/>
intCounter = 1<br/>
For Each objUser In objOU<br/>
If objUser.sAMAccountName = "test*" then<br/>
objGroup.add(objUser.ADsPath)<br/>
intCounter = intcounter +1<br/>
End If<br/>
Next<br/>
WScript.Echo strGroup & " has " & intCounter & " new members"

Kindly guide me.
Thanks in advance.



View the full article
 
Back
Top