' This VBScript code creates a large number of users with incremented user names
' e.g. User1, User2, User3, ....
' ---------------------------------------------------------------
' From the book "Active Directory Cookbook" by Robbie Allen
' ISBN: 0-596-00466-4
' ---------------------------------------------------------------
' ------ SCRIPT CONFIGURATION ------
intNumUsers = 1000 ' Number of users to create
strParentDN = "<ParentDN>" ' e.g. ou=bulk,dc=emea,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
' Taken from ADS_USER_FLAG_ENUM
Const ADS_UF_NORMAL_ACCOUNT = 512
set objParent = GetObject("LDAP://" & strParentDN)
for i = 1 to intNumUsers
strUser = "User" & i
Set objUser = objParent.Create("user", "cn=" & strUser)
objUser.Put "sAMAccountName", strUser
' CORRECTION: If you don't set userAccountControl, then by default
' the value of 514 (normal account + disabled) will be set for it.
' In this instance by setting it to 512, the account will not
' be disabled, and if you have password complexity enabled in
' your forest, the script will fail because a password was not
' set prior to the account being enabled. The solution is to
' not set userAccountControl here.
' objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
objUser.SetInfo
objUser.SetPassword(strUser)
objUser.AccountDisabled=FALSE
objUser.SetInfo
WScript.Echo "Created " & strUser
next
WScript.Echo ""
WScript.Echo "Created " & intNumUsers & " users"
|