7

I'd like to create 100 users just for test purposes of my Exchange Server.

Is there a way to batch do this using random names, etc?

7 Answers7

5

If you have a Windows Server 2008 R2 Domain Controller available, you can run the following PowerShell script to create some dummy users. You'll still have to use Active Directory Users and Computers to mailbox enable these users, but you can select all the users and do it in bulk.

You can change the number of users created, and the password on the accounts as well. Note that the password must comply with any password requirements (complexity, length etc.) in effect.

Save as NewUsers.ps1 and run from the Active Directory Module for Windows PowerShell.

[1..100] | % { New-ADUser "User$_" -AccountPassword (ConvertTo-SecureString -AsPlainText -Force -String "P#$$w0rd") -Enabled $True }
Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
Ben Pilbrow
  • 12,041
  • 5
  • 36
  • 57
4

On the command prompt, look at "dsadd":

http://technet.microsoft.com/en-us/library/cc731279(v=WS.10).aspx

or "net user":

http://support.microsoft.com/kb/251394

You can use excel or notepad etc to prepare a list of commands to paste into a command prompt, or make a batch file.

simon
  • 714
  • 1
  • 7
  • 21
4

Here is a script that I made to use dsadd. I have a one line batch file that imports all of my new users every year:

(There might be a better way to display this, but I haven't had coffee yet.)

for /F "tokens=1,2,3,4 delims=," %%i in (freshmen09.csv) do dsadd user "cn=%%j %%i,ou=2013,ou=students,dc=[domain],dc=org" -samid %%k -pwd "%%l" -upn %%k@[domain].org -fn "%%j" -ln "%%i" -display "%%j %%i" -memberof "cn=GL 2013,ou=2013,ou=students,dc=[domain],dc=org" -disabled no -mustchpwd yes -hmdrv U: -hmdir "\\[network home directory]\2013\%%k"

This take 4 columns from a CSV file: Last Name, First Name, Username, Password

  • It creates a user for each row in the file,
  • Puts them into the desired OU,
  • Sets the password,
  • Adds them as a member of a group,
  • Enforces that the password must be changed when the user first logs in,
  • Sets the home directory to the appropriate place on our network share.

I have tried to get this to create email addresses automatically, but I have had inconsistent results. It is easy enough to just select all the users at once in Active Directory Users and Computers and setup Exchange Mailbox from there. Very simple, and much easier than figuring that part out with DSADD.

DSADD has many other parameters as well. You can basically make it set any user properties that you want. Simple, easy, and fast.

One failure: Username collisions need to be handled manually. We occasionally have students with names like James Smith and Jonathon Smith. If you have a system to prevent collisions ahead of time, perfect. If not, I recommend redirecting the output of the bat file to a text file and just search for "Fail" in the results.

freshmen09.bat > freshmen09_output.txt

(There is likely a much better way to do this part...)

minamhere
  • 859
  • 7
  • 18
3

Check the script here: http://blogs.technet.com/b/keithcombs/archive/2008/11/26/filling-up-active-directory-with-some-test-data.aspx

Make sure your internal domain is CONTOSO.COM, or else change the script. You will have to create mailboxes for all the users afterwards, but that is pretty easy to do in bulk.

CarloBaldini
  • 583
  • 2
  • 8
3

Or we can use this command dsadd user here is one article which is talking about who to create user and folders.

set FirstName=Graice
set LastName=tsai
set LogonName=graice
set pass=welcome
dsadd user ”CN=%LogonName%, ou=FTPUsers, dc=yourDCname,dc=com” -pwd %pass% -pwdneverexpires yes -samid %LogonName% -upn %LogonName% -ln %LastName% -fn %FirstName%
dsmod user ”CN=%LogonName%, ou=FTPUsers, dc=yourDCname,dc=com” -disabled no
dsmod group ”CN=FTP Users, ou=FTPUsers, dc=yourDCname,dc=com” -addmbr ”cn=%LogonName%, ou=FTPUsers, DC=yourDCname, DC=com”
Abhijeet Kasurde
  • 983
  • 9
  • 20
Jason
  • 31
  • 1
3

A colleague and myself came up with a useful script which generates 5000 users to test the ldap user limits of our java client. It was run on a Windows Server 2008 server using the Administrator account.

Simply save the following to a run.cmd file, adjust the domain name and OU, and run it using a command prompt:

@echo off
set FirstName=test
set LastName=user
set LogonName=testuser_new
set pass=Welcome_1234
setlocal enableextensions enabledelayedexpansion

FOR /L %%A IN (1,1,5000) DO (

    echo %LogonName%_%%A

    dsadd user "CN=%LogonName%_%%A, CN=Users, dc=fist,dc=com" -pwd %pass% -pwdneverexpires yes -samid %LogonName%_%%A -upn %LogonName%_%%A -ln %LastName% -fn %FirstName%
    dsmod user "CN=%LogonName%_%%A, CN=Users, dc=fist,dc=com" -disabled no

)

endlocal

You can create more users just by adjusting the limit in the FOR loop.

gtirloni
  • 5,746
  • 3
  • 25
  • 52
2

This could help you in an easy way: http://testools.blogspot.com/2013/01/how-to-create-several-users-in-active.html

This is better if you want to have specific names for each user, different than user1, user2, etc.

duco1202
  • 21
  • 1