Create Users for Testing Purposes

Posted on January 7, 2009 by Daniel Petri in Active Directory with 0 Comments

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 .

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 – [email protected]) 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:

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 – [email protected] 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:

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:

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:

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.

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:

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):

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.

Sponsored

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.

Sponsored

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:

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:

(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 .

Links

Step-by-Step Guide to Bulk Import and Export to Active Directory

Importing and exporting directory information

Using LDIFDE to Import and Export Directory Objects to Active Directory – 237677

How to Use Csvde.exe to Import Contacts into Active Directory – 300409

Sponsored