Recipe 6.2 Creating a Large Number of Users

6.2.1 Problem

You want to create a large number of user objects, either for testing purposes or to initially populate Active Directory with your employee, customer, or student user accounts.

6.2.2 Solution

The following examples will create 1,000 users in the domain under the Bulk OU. The password is set, but no other attributes are configured. You can modify the examples to populate whatever attributes you need. Using a command-line interface
> for /L %i in (1,1,1000) do dsadd user cn=User%i,ou=bulk,dc=rallencorp,dc=com -pwd[RETURN] 
User%i Using VBScript
' This code creates a large number of users with incremented user names
' e.g. User1, User2, User3, ....
intNumUsers = 1000         ' Number of users to create
strParentDN = "<ParentDN>" ' e.g. ou=bulk,dc=emea,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------


set objParent = GetObject("LDAP://" & strParentDN)
for i = 1 to intNumUsers
   strUser = "User" & i
   Set objUser = objParent.Create("user", "cn=" & strUser)
   objUser.Put "sAMAccountName", strUser
   objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT
   WScript.Echo "Created " & strUser
WScript.Echo ""
WScript.Echo "Created " & intNumUsers & " users"

6.2.3 Discussion

Using ADSI and even the new DS command line utilities on Windows Server 2003, you can create hundreds and even thousands of users easily and quickly. I ran both the CLI and VBScript solutions in a test domain, which create 1,000 user objects, on a single processor machine. The VBScript solution took less than 1.5 minutes and the CLI solution took less than 5 minutes. Admittedly, they are not populating very many attributes, but it shows that you can quickly populate Active Directory with user accounts very easily. You can also modify the examples to pull from a data source, such as an employee database, and use real data.

6.2.4 See Also

Recipe 6.1 for creating a user

    Chapter 3. Domain Controllers, Global Catalogs, and FSMOs
    Chapter 6. Users
    Appendix A. Tool List