For my tenant, I needed a bit more cloud-synced test/demo users, and as always… It’s better to use PowerShell for that 🙂 In this blog post, I will show you how to create them using RobBridgeman’s ADImporter project.
What is ADImporter?
“When you need to simulate a real Active Directory with thousands of users you quickly find that creating realistic test accounts is not trivial. Sure enough, you can whip up a quick PowerShell one-liner that creates any number of accounts, but what if you need real first and last names? Real (existing) addresses? Postal codes matching phone area codes? I could go on. The point is that you need two things: input files with names, addresses etc. And script logic that creates user accounts from that data. This Repo provides both.”
Source: https://github.com/RobBridgeman/ADImporter/tree/master#adimporter
Preparation
Below are the steps that I used to create 5000 test accounts in Active Directory so that Entra Cloud Sync could add them to Entra ID. The reason I needed more accounts was that I created scripts that would run for 10 or 20 accounts, but started to show performance issues with 100 or 500 accounts, and needed more performance improvements and error handling when reaching 1000 accounts, etc. 🙂
Download the files needed from GitHub
Use Git to clone the repository to your local drive on a system that has access to Active Directory and the PowerShell Active Directory module installed. (git clone https://github.com/RobBridgeman/ADImporter.git) Or download the files as a zip file.
Edit the files for your environment
Before running the CreateDemoUsers.ps1 script, edit it and update the values to match your environment.

I changed the values for the OU in which the users will be created, the InitialPassword (Which I bulk change afterward using the script listed in one of the next chapters), the orgShortName, and the dnsDomain (This should match your environment’s UPN Suffix and should be added as a Domain in Entra ID if you will sync these accounts to Entra ID), the Company, and I left the department values default.
The most important thing is… I configured the userCount value to 50 so that it wouldn’t take that long 😉 The higher the value, the longer it takes, but it was pretty quick in the 5000-user run I did previously.
After changing and saving CreateDemoUsers.ps1, check the addresses, postalareacode, firstname, and lastnames text files. (Beware, some are large.) Add, remove, or change them as needed. The addresses.txt wasn’t accurate on the Country (NL instead of DE in some of them)
Run the script
After changing the script and the text files (where needed), you can run the script. (You can ignore the UT-7 warnings)

It created 50 new users, as configured, but now they all have the same password. And because I sync them to Entra ID, I didn’t think it was a good idea, and I wanted to change that…
Bulk changing the passwords of the users
I searched for a complex password function, changed it a bit, and let it change all the passwords of the users specified in the Searchbase value:
<div class="cm-line">function New-ComplexPassword {</div><div class="cm-line"> param ([int]$length = 12)</div><div class="cm-line"></div><div class="cm-line"> $lower = 'abcdefghijklmnopqrstuvwxyz'</div><div class="cm-line"> $upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</div><div class="cm-line"> $digits = '0123456789'</div><div class="cm-line"> $symbols = '!@#$%^&*()'</div><div class="cm-line"></div><div class="cm-line"> $allChars = $lower + $upper + $digits + $symbols</div><div class="cm-line"> $password = -join ((1..$length) | ForEach-Object { $allChars[(Get-Random -Minimum 0 -Maximum $allChars.Length)] })</div><div class="cm-line"></div><div class="cm-line"> # Ensure at least one character from each set</div><div class="cm-line"> $password += $lower[(Get-Random -Minimum 0 -Maximum $lower.Length)]</div><div class="cm-line"> $password += $upper[(Get-Random -Minimum 0 -Maximum $upper.Length)]</div><div class="cm-line"> $password += $digits[(Get-Random -Minimum 0 -Maximum $digits.Length)]</div><div class="cm-line"> $password += $symbols[(Get-Random -Minimum 0 -Maximum $symbols.Length)]</div><div class="cm-line"></div><div class="cm-line"> # Shuffle the password</div><div class="cm-line"> $password = -join ($password.ToCharArray() | Sort-Object { Get-Random })</div><div class="cm-line"> return $password.Substring(0, $length)</div><div class="cm-line">}</div><div class="cm-line"></div><div class="cm-line">foreach ($User in Get-ADUser -SearchBase "OU=Users,OU=Corp,DC=psif,DC=local" -Filter *) {</div><div class="cm-line"> Write-Output ("Changing Password for user {0}" -f $user.SamAccountName)</div><div class="cm-line"> Set-ADAccountPassword -Identity $User -Reset -NewPassword (ConvertTo-SecureString $(New-ComplexPassword -length 20)-AsPlainText -Force) </div><div class="cm-line">}</div>
As shown in the screenshot below, the New-ComplexPassword Function generates a new password each time it runs. It has used that to give all newly created users a random password by running the script above 🙂 (Change the OU value and be sure not to target this to non-demo/production user accounts!)

When running the script, it will show you the user whose password is being changed.

Add users to random groups
And to prepare the demo accounts a bit more, I decided to also add them to a set of groups from a specific OU 🙂 Using the script below, I added all users to ten random groups within the OU specified in the $Groups variable. (You can change the 1..3 to 1..5 for 5 groups, for example) This will also take a while, depending on how many users are created and added to these groups…
<div class="cm-line">$Groups = Get-ADGroup -SearchBase "OU=Groups,OU=Corp,DC=psif,DC=local" -Filter *</div><div class="cm-line">1..3 | ForEach-Object {</div><div class="cm-line"> foreach ($User in Get-ADUser -SearchBase "OU=Users,OU=Corp,DC=psif,DC=local" -Filter * ) {</div><div class="cm-line"> Add-ADGroupMember -Identity $($groups | Get-Random) -Members $User </div><div class="cm-line"> }</div><div class="cm-line">}</div>
After running this, the user will be part of 3 random groups from this list (This is from my environment; create your own set or point to an existing OU with demo groups):

Result:

Entra ID
After creating all the users, resetting their passwords, and adding them to random groups… The users were also visible in Entra ID due to Entra Cloud Sync. It took a while to sync the initial 5000 user accounts; this batch of 50 was much quicker.
And the same user as above from Active Directory is now also in Entra ID with the same groups (Which are also synced by Entra Cloud Sync)

Note: If you have enabled Password Write-Back and Self-Service Password Reset… Be sure not to enable it for these users, or disable it…
Wrapping up
And that’s how you can bulk create demo accounts for testing scripts, nice and a lot better than click-ops 😉 Have a lovely weekend!
