Batch Adding AD Users
October 16, 2007
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.
Technorati Tags: Work, Scripting, Active Directory, AD
Posted in
I'm a full time network administrator, working for a large company in the automotive industry. I enjoy spending time with my family, when I get away from work that is. I also enjoy photography, and computer programming.
content rss

June 25th, 2008 at 21:49
[...] point for a lot of common questions. So next time a task requires you to go through and modify, or add, or even delete options, sometimes a script is just as quick. something we should get around to, as [...]