Table of Contents
- What’s the Smartest Way to Bulk-Create Active Directory Users Without Headaches?
- Why I Need Lots of Test Users
- Creating Users With a Simple Script
- Making Users Look Real
- Step 1: Download the Script
- Step 2: Set Execution Policy
- Step 3: Edit the Script
- Step 4: Check the CSV File
- Step 5: Run the Script
- Step 6: See the Results
- Giving Users Mailboxes
- Tips for Success
What’s the Smartest Way to Bulk-Create Active Directory Users Without Headaches?
Setting up a test network helps me learn and practice. Sometimes, I need a lot of user accounts to make my tests feel real. If I only use fake names like User1 or User2, it looks odd. I want users that seem real, with names that make sense. Here’s how I do it, step by step.
Why I Need Lots of Test Users
When I’m preparing for big changes or migrations, I want to be sure everything works. Creating hundreds or thousands of test users by hand takes forever. Scripts help me save time and avoid mistakes. The best part? I can make the users look real, not just random numbers.
Creating Users With a Simple Script
First, use a script to make 1,000 users in Active Directory. Here’s a basic way to do it:
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 this as createusers.vbs and run it on my domain controller. It gives me 1,000 users, but they’re called UserNo1, UserNo2, and so on. They’re not enabled and have no passwords, but I can fix that later.
Making Users Look Real
Fake names are fine for some things, but I want my test to feel real. I use a random name generator to make a list of names. Then, I use a PowerShell script to create users with those names.
What I Do:
Step 1: Download the Script
Get the bulk user creation script and a CSV file with names. I put them on my desktop.
Step 2: Set Execution Policy
Open PowerShell and type:
Set-ExecutionPolicy Unrestricted
This lets me run the script.
Step 3: Edit the Script
Open newusers.ps1 in Notepad. I change the domain details to match my setup, like this:
$TargetOU = [ADSI]"LDAP://CN=Users,DC=yourdomain,DC=com"
I make sure the script points to my domain.
Step 4: Check the CSV File
The CSV file, usernames.csv, has columns for first name, last name, login, and password. Each row is a user.
Step 5: Run the Script
Go to the folder with the script:
cd Desktop/New_Users ./Newusers.ps1
The script reads each row from the CSV file and creates a user in Active Directory. Each user gets a name, login, and password.
Step 6: See the Results
Open Active Directory. I see all the new users. They have real names and are ready to use.
Giving Users Mailboxes
After making the users, I want them to have mailboxes. That way, I can test email too. I use another PowerShell command:
Get-User -OrganizationalUnit "yourdomain.com/users/" -ResultSize Unlimited | Enable-Mailbox -Database "Mailbox-Database"
If some users already have mailboxes, I might see a few errors. That’s okay. The rest get mailboxes.
Tips for Success
- Always double-check the domain details in the script.
- Make sure the CSV file has no typos.
- If you see errors, read them carefully. Most are easy to fix.
- Practice on a test network before using scripts in production.
With these steps, I can quickly build a test environment that feels real. This makes my work easier, safer, and more effective.