How can I quickly create 100 users on my Active Directory for testing purposes?
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 }
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.
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...)