KB ID 0000784
Problem
Update Jan 2023: Feel free to use this Bulk-Create-AD-Users-Script (Just remeber to change the domain details in the “Global Variables’ Sections to give you 10o0 users, with sensible names addreeses etc.
Having a test network, is great for both learning, and testing. I’ve got some major migrations coming up in the next few months, so I’m in the process of running up some new test servers. I usually run a quick .vbs file like this;
Set objRootDSE = GetObject("LDAP://rootDSE") Set objContainer = GetObject("LDAP://cn=Users," & _ objRootDSE.Get("defaultNamingContext")) For i = 1 To 1000 Set objLeaf = objContainer.Create("User", "cn=UserNo" & i) objLeaf.Put "sAMAccountName", "UserNo" & i objLeaf.SetInfo Next WScript.Echo "1000 Users created."
Save that as createusers.vbs and run it on your domain controller and it will churn out 1000 users (named UserNo1 – UserNo1000). They will be disabled, with no passwords, but that can be rectified with a few mouse clicks.
But I want something a little more realistic, so I found a random name generator, and decided to have a script to create 1000 users that were a little more ‘lifelike’.
Solution
1. Download this zip file, and extract it to your desktop. To run the script you will need to set your Execution Policy with the following command;
2. You will need to change a couple of lines in the newusers.ps1 file open it with notepad and change the domain details to match yours;
$TargetOU = [ADSI]“LDAP://CN=Users,DC=pnl,DC=com” foreach ($user in import-csv usernames.csv) { $newUser = $TargetOU.Create(“user”,“cn=” +$user.login) $newUser.put(“sn”, $user.Last) $newUser.put(“DisplayName”, $user.First + ” “ +$user.Last) $newUser.put(“givenName”, $user.First) $newUser.put(“sAMAccountName”,$user.login) $newUser.put(“userPrincipalName”,$user.login + “@pnl.com”) $newUser.SetInfo() $newUser.SetPassword($user.password) $newUser.put(“userAccountControl”, 512) $newUser.SetInfo() }
3. Change directory to the folder with your script in, and run it, it will put the details from the usernames spreadsheet;
cd Desktop/New_Users ./Newusers.ps1
3. Look in Active Directory and there are your new users.
Bulk Creating Mailbox’s for your Users
Now I’ve got my users in AD, I want them all to have a mailbox, so a quick PowerShell command;
It will throw out the odd error (e.g. if it finds users that are already mail enabled), that’s OK.
Related Articles, References, Credits, or External Links
NA