Share this post!

Ever wanted to create a number of Active Directory test user accounts, but didn’t want to use incrementing accounts like Test01, Test02, Test03, etc.? I’ve often used United States presidents and vice presidents for my test accounts. The usernames are far more interesting that way! For anyone who would like to do the same, I’ve created a very simple PowerShell script, that simply needs two lines modified at the top, to be reusable for other environments. Once run against Active Directory, you’ll have 77 accounts that can be nested into groups or used for various testing functions. Check it out and enjoy!

Update: I asked Chat GPT to build me some inline documentation for the script and it did a pretty decent job!

# Set the domain name for the user accounts
$userdomain = ""

# Set the organizational unit path for the user accounts
$organizationalunitpath = "ou=Politicians,ou=users,ou=company,dc=mydomain,dc=com"

# Define an array of politician names
$politicians = @(
("Joe","Biden" ),
("Al","Gore" ),

# Import the Active Directory module
Import-Module ActiveDirectory

# Loop through each politician in the array
foreach ($politician in $politicians){

# Extract the first and last name of the politician from the array
$firstname = $politician[0]

$lastname = $politician[1]

# Construct the username for the politician
$username = "$firstname.$lastname"

# Construct the user principal name for the politician
$userprincipalname = "$username@$userdomain"

# Write a message to the console indicating that a user account is being created
Write-host "Creating user account for $username"

# Create a new Active Directory user account
New-ADUser -Name $username `
-UserPrincipalName $userprincipalname `
-GivenName $firstname `
-Surname $lastname `
-Path $organizationalunitpath `
-Enabled $true `
-PasswordNotRequired $true

Share this post!