Create Users for Testing Purposes

How can I create a large number of users for testing purposes?

If you want to create a large amount of test user accounts in your domain or local accounts on your workstation, you can do so in more than one way. On this page I’ll try to list a few of these methods.

If you happen to have some nice scripts that can do the same job in other methods (oh yes, there are other methods), please do send me an e-mail and I’ll upload it to this page smtp.
Windows Server 2003 AD Note: Windows Server 2003 Active Directory is configured, by default, to request that any user that you create will have a password that is complex and with a minimum of 7 characters. Some methods described here (mainly method #3 and #4) cannot add the password attribute to a user account. In order for these methods to work in your test environment you must first disable the password requirement for the Windows Server 2003-based Domain. Read my Disable Password Requirements in Windows Server 2003 Domains article for more info.
Method #1: By using the NET USER command
NET USER is an old NT-related user manipulation command. I will not list all of it’s attributes here (you can find for yourself by going to the Help and Support site on your computer). I do not usually use the NET USER command in an AD environment, mostly due to the fact that it is not tailored for AD objects at all, but still, it can be used for our needs.
You can use the FOR and NET USER commands to accomplish the task in a “quick and dirty” way, without scripting or writing any code. For example, if you type from the command prompt:

​
This will result in creating 500 new users, named MyUser1, MyUser2, etc. You can, of course, customize the FOR command's parameters. See the FOR command help for more options.
You can also set the user's password (in this case - P@ssw0rd) in the same manner:
​
You can delete all those users by running the following command:
​
Note: If run on a stand alone W2K Server, W2K PRO or on an XP machine, this script will create local users. If run on a DC it will create users in the USERS Container in the AD. However, doing so on a domain controller will not create fully AD-compatible users (as you can clearly see if you open one of these users and try to find the User Principal Name - UPN - field).
Note: If you're using a W2K PRO or XP PRO computer that is connected to an Active Directory network and you wish to create local users on that computer - run the command above. However, if you want, from that computer, to create users in the Active Directory database on the DC, use this command instead:
​
To create users with pre-configured names (for example - a file with all your company's usernames or a database with usernames) create a text file like this one:
​
moshe
yossy
gabi
ran
bijo
baruch
bibi

Name the file USERS.TXT and place it in a directory.
Now open a CMD in that directory and run the following command:

​
This will create user accounts with the names found in the USERS.TXT file, all with the same password - P@ssw0rd. You don't have to use the /domain switch unless you want to.
See the NET USER or NET USERS command help for more options.
Method #2: By using the DSADD USER command
DSADD USER is a command found in Windows Server 2003, and is specifically tailored for AD usage. Almost any user-related attribute can be set by using this command.
Note: The DSADD command is not just about adding users. Run DSADD /? in your CMD window and see for yourself.
For example, if you type from the command prompt:
​dsadd user "cn=Test User,ou=Test OU,dc=dpetri,dc=net" -samid testuser -upn [email protected] -fn Test -ln User -display "Test User" -pwd P@ssw0rd -disabled no

This will create one user called “Test User” with all the necessary information (and as I said earlier, more attributes can be easily configured in the same way).
Lamer Note: Note that you want to use the same syntax as above, you must first create the “Test OU” OU in you AD, and also change the DN of the domain to the name of YOUR domain.
However we would like to create many users for testing purposes. Therefore we can use the FOR command like we did before:

​FOR /L %i in (1,1,500) DO dsadd user "cn=Test User%i,ou=Test OU,dc=dpetri,dc=net" -samid testuser%i -upn testuser%[email protected] -fn Test -ln User%i -display "Test User%i" -pwd P@ssw0rd -disabled no

This script will create 500 users called Test User1, Test User2 and so on.
Like with NET USER, the DSADD USER command can be used along with a text or CSV file that contains a list of all the users that you want to build.
Create a text file like this one:

​Blue,Kelly,bluek,04-6545645
Ben-Sachar,Ido,bensachari,03-7634545
Fluegel,Jay,fluegelj,03-9875765
Grande,Jon,grandej,02-6674534
Hankin,Alex,hankina,04-8856476
Jiang,George,jiangg,08-7636344
Kelly,Robert,kellyr,03-5568336
Kelly,Bob,kellyb,03-9567474
Li,Yuhong,liy,02-5462272
Moreland,Barbara,morelandb,04-88293922
Naik,Mandar,naikm,03-5531190
O'Donnell,Claire,odonnellc,03-5111930
Smith,John,smithj,03-8102201

Name the file USERS.TXT and place it in a directory.
Now open a CMD in that directory and run the following command:

​for /F "eol=; tokens=1,2,* delims=," %%i in (users.txt) do dsadd user "cn=%%j %%i,ou=Test OU,dc=dpetri,dc=net" -samid %%k -upn %%[email protected] -fn %%j -ln %%i -display "%%j %%i" -pwd P@ssw0rd -disabled yes

This will create user accounts with the names found in the USERS.TXT file.
Imagine the power of such a script!
Method #3: By using the CSVDE command
CSVDE is a command that can be used to import and export objects to and from the AD into a CSV-formatted file. A CSV (Comma Separated Value) file is a file easily readable in Excel.
I will not go to length into this powerful command, but I will show you some basic samples of how to import a large number of users into your AD. Of course, as with the DSADD command, CSVDE can do more than just import users. Consult your help file for more info.
For example, lets say I would like to create a number of very simple users. Just the necessary information, nothing more.
Create a text file like this one:

​dn,sAMAccountName,userPrincipalName,userAccountControl,objectClass
"CN=Amie Baldwin,OU=Test OU,DC=dpetri,DC=net",amieb,[email protected],512,user
"CN=Scott Culp,OU=Test OU,DC=dpetri,DC=net",scottc,[email protected],512,user
"CN=Derek Graham,OU=Test OU,DC=dpetri,DC=net",derekg,[email protected],512,user
"CN=Stephanie Bourne,OU=Test OU,DC=dpetri,DC=net",stephanieb,[email protected],512,user
"CN=Matthew Dunn,OU=Test OU,DC=dpetri,DC=net",matthewd,[email protected],512,user

Name the file USERS.CSV and place it in a directory.
Open a CMD in that directory and run the following command:

​
(use your own path)
This will create 5 user accounts with the names found in the USERS.CSV file.
Note: Note that CSVDE, unlike DSADD USER, cannot import passwords into the AD. For that reason, unless you specify the  userAccountControl attribute as 512, the users that will be imported will be disabled by default. Also remember that you must  Disable Password Requirements in Windows Server 2003 Domains in order for this command to work in Windows Server 2003-based domains.
Now lets say I would like to create the same users but this time with associated mailboxes stored on my Exchange server called SERVER100.
Create a text file like this one (select all and just copy):
​DN,objectClass,name,homeMDB,cn,displayName,mail,givenName,proxyAddresses,sAMAccountName,sn,userAccountControl,userPrincipalName,homeMTA,msExchHomeServerName,mailNickname,countryCode,c,l,homePhone,mobile,telephoneNumber,co,wWWHomePage
"CN=kuku levi,OU=Test OU,DC=dpetri,DC=net",user,kuku levi,"CN=Mailbox Store (SERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",kuku levi,kuku levi,[email protected],kuku,SMTP:[email protected];X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi';g=kuku';,kukul,levi,512,[email protected],"CN=Microsoft MTA,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=SERVER100,kukul,376,IL,Tel-Aviv,03-4534545,051-345345,03-4534545,ISRAEL,petri.com
"CN=momo levi,OU=Test OU,DC=dpetri,DC=net",user,momo levi,"CN=Mailbox Store (SERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",momo levi,momo levi,[email protected],momo,SMTP:[email protected];X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi';g=momo';,momol,levi,512,[email protected],"CN=Microsoft MTA,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=SERVER100,momol,376,IL,Tel-Aviv,03-9879878,053-878345,03-9879878,ISRAEL,www.msn.co.il
"CN=jojo levi,OU=Test OU,DC=dpetri,DC=net",user,jojo levi,"CN=Mailbox Store (SERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",jojo levi,jojo levi,[email protected],jojo,SMTP:[email protected];X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi';g=jojo';,jojol,levi,512,[email protected],"CN=Microsoft MTA,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=SERVER100,jojol,376,IL,Tel-Aviv,03-2424478,053-654654,03-2424878,ISRAEL,www.cnn.com
"CN=bubu levi,OU=Test OU,DC=dpetri,DC=net",user,bubu levi,"CN=Mailbox Store (SERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",bubu levi,bubu levi,[email protected],bubu,SMTP:[email protected];X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi';g=bubu';,bubul,levi,512,[email protected],"CN=Microsoft MTA,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=SERVER100,bubul,376,IL,Tel-Aviv,03-8768767,053-456658,03-8768767,ISRAEL,www.cnn.com
"CN=dudu levi,OU=Test OU,DC=dpetri,DC=net",user,dudu levi,"CN=Mailbox Store (SERVER100),CN=First Storage Group,CN=InformationStore,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",dudu levi,dudu levi,[email protected],dudu,SMTP:[email protected];X400:c=us';a= ';p=Dpetri';o=Exchange';s=levi';g=dudu';,dudul,levi,512,[email protected],"CN=Microsoft MTA,CN=SERVER100,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Dpetri,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=dpetri,DC=net",/o=Dpetri/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=SERVER100,dudul,376,IL,Tel-Aviv,03-5645446,051-978879,03-5645446,ISRAEL,www.disney.com

Note: The text might look a bit garbled, but if you copy and paste inside a new text file you’ll see it fine. Excel will also help you with editing the file.

Lamer Note: This might be a good point to remind you to USE YOUR OWN NAMES!!!
Name the file USERS.CSV and place it in a directory.
Open a CMD in that directory and run the following command:

​
(use your own path)
This will create 5 user accounts with the names found in the USERS.CSV file, alongside with some nice attributes for each user.
Method #4: By using the LDIFDE command
Like CSVDE, LDIFDE is a command that can be used to import and export objects to and from the AD into a LDIF-formatted file. A LDIF (LDAP Data Interchange Format) file is a file easily readable in any text editor, however it is not readable in programs like Excel. The major difference between CSVDE and LDIFDE (besides the file format) is the fact that LDIFDE can be used to edit and delete existing AD objects (not just users), while CSVDE can only import and export objects.

Like in CSVDE, I will not go to length into this powerful command, but I will show you some basic samples of how to import a large number of users into your AD. Of course, as with the DSADD command, LDIFDE can do more than just import users. Consult your help file for more info. Here too, remember to  Disable Password Requirements in Windows Server 2003 Domains in order for this command to work in Windows Server 2003-based domains.
For example, just like with the CSVDE command, lets say I would like to create a number of very simple users. Just the necessary information, nothing more.
Create a text file like this one:
​​dn: CN=Amie Baldwin,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Amie Baldwin
objectClass: user
name: Amie Baldwin
sAMAccountName: amieb
telephoneNumber: 555-1234
userAccountControl: 514
userPrincipalName: [email protected]
dn: CN=Scott Culp,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Scott Culp
department: Accounting
objectClass: user
name: Scott Culp
sAMAccountName: scottc
telephoneNumber: 555-1236
userAccountControl: 512
userPrincipalName: [email protected]
dn: CN=Derek Graham,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Derek Graham
department: Accounting
objectClass: user
name: Derek Graham
sAMAccountName: derekg
telephoneNumber: 555-1239
userAccountControl: 512
userPrincipalName: [email protected]
dn: CN=Stephanie Bourne,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Stephanie Bourne
department: Accounting
objectClass: user
name: Stephanie Bourne
sAMAccountName: stephanieb
telephoneNumber: 555-1239
userAccountControl: 512
userPrincipalName: [email protected]
dn: CN=Matthew Dunn,OU=Test OU,DC=dpetri,DC=net
changetype: add
cn: Matthew Dunn
department: Accounting
objectClass: user
name: Matthew Dunn
sAMAccountName: matthewd
telephoneNumber: 555-1230
userAccountControl: 512
userPrincipalName: [email protected]

Note that unlike the CSV-formatted file, the LDIF file is quite easy to understand and edit in Notepad. However, you may find it easier to edit a large number of users via Excel than through Notepad, that’s why the CSV-formatted file will still be easier to manipulate than the LDIF-formatted file.
Name the file USERS.LDF and place it in a directory.
Open a CMD in that directory and run the following command:

​ldifde -i -f users.ldf

(use your own path)
This will create 5 user accounts with the names found in the USERS.LDF file.
Since the only difference between the CSVDE and LDIFDE commands is the file format I will stop here. Remember that you can add almost any user-configurable attribute by using these commands. Test them on your own, and if you come up with a truly amazing result please share it with us smtp.

Links

Step-by-Step Guide to Bulk Import and Export to Active Directorylink out ico
Importing and exporting directory informationlink out ico
Using LDIFDE to Import and Export Directory Objects to Active Directory – 237677link out ico
How to Use Csvde.exe to Import Contacts into Active Directory – 300409link out ico