Bulk User creation in Active Directory is made easy with the VBScript given here. Thousands of users can be created at the click of a button. Lets go step by step creating this script. Open notepad and save it by typing “create-users.vbs” INCLUDING the double quotes. This will create a file with a .vbs extension instead of .txt. Then type the following code.
set objCON = GetObject("LDAP://CN=Users, DC=example, DC=net")
Set objUser = objCON.Create("user","CN=User1")
objUser.Put "sAMAccountName", "user1"
objUser.SetInfo()
This will create an user with name “User 1” and login name “user1” in the active directory domain example.net in the Users container. By default the user account will be disabled to create account and enable them using the script itself add the following code to the end of the code above
objUser.AccountDisabled = False
objUser.SetInfo()
Now we move on to the real part of creating users in bulk. I’ll be showing you how to create 100 users with generic names like user1, user2, …. user100 using a FOR loop.
For i = 1 to 100
set objCON = GetObject("LDAP://CN=Users, DC=example, DC=net")
Set objUser = objCON.Create("user","CN=User" & i)
objUser.Put "sAMAccountName", "user" & i
objUser.SetInfo()
objUser.AccountDisabled = False
objUser.SetInfo()
Next
This will create 100 users and enable then automatically. If you want the users to be disbaled just remove the two lines above the “Next” statement. To set passwords for users add a line after the first objUser.SetInfo()
objUser.SetPassword "password"
So the final script is given below
For i = 1 to 100
set objCON = GetObject("LDAP://CN=Users, DC=example, DC=net")
Set objUser = objCON.Create("user","CN=User" & i)
objUser.Put "sAMAccountName", "user" & i
objUser.SetInfo()
objUser.AccountDisabled = False
objUser.SetPassword "password"
objUser.SetInfo()
Next
If you want to create the users inside an OU (Organizational Unit), in the GetObject function replace CN=Users with OU=OUname
Leave a Reply