Part of the work I’m doing while I’m out had me add a collection of test users. This could have been quite a task, had it not been for the nice features of vbscript.
We’re performing some testing on one of our applications, and needed to batch add 100 users into Active Directory to perform the testing. This is the code I ended up using.
dim strUser
Dim objRootLDAP, objContainer, objNewUser, objGroup
set objRootLDAP = GetObject("LDAP://rootDSE")
set objContainer = GetObject("LDAP://cn=Users," & _
objRootLDAP.Get("defaultNamingContext"))
set objGroup = GetObject("LDAP://CN=App_Users,CN=Users,DC=testdmn,DC=com")
for i = 1 to 100
strUser = "Test" & i
set ObjNewUser = objContainer.Create("User", "cn=" & strUser)
objNewUser.Put "sAMAccountName", strUser
objNewUser.Put "cn", strUser
objNewUser.Put "givenName", strUser
objNewUser.Put "displayName", strUser
objNewUser.Put "userPrincipalName", strUser & "@testdmn.com"
objNewUser.SetInfo
objNewUser.SetPassword("password")
objNewUser.AccountDisabled = FALSE
objNewUser.SetInfo
objGroup.Add("LDAP://cn=" & strUser & ",CN=Users,DC=testdmn,DC=com")
objNewUser = null
Next
It logins to the AD server, opens a connection, creates a user, adds them to the group, and moves onto the next user. When you open the AD Users & Computers now, you’ll see 100 Test# users.