
When you need to test Active Directory in a lab with sample users, creating sufficiently realistic test accounts is a time consuming and tedious process. There are a few quick scripts for creating something similar but many of them only create basic users which don’t emulate a production environment very well.
This script will create users with the following attributes:
LAB.local
\---Company
\---Users
This is the OU in your lab where the user accounts will reside:
# User properties
# Base OU for users, sub OU for country code will be created
$BaseOU = "OU=Users,OU=Company,DC=lab,DC=local"
The domain details include the org short name and full DNS suffix. This will be used, as the comments say, to construct the UPNs for each user.
# Domain Details
$orgShortName = "LAB" # This is used to build a user's sAMAccountName
$dnsDomain = "lab.local" # Domain is used for e-mail address and UPN
A list of companies within the organisation a user could belong to. Some organisations have smaller companies within. This helps model that structure. In most cases this can be left as-is depending on what you are trying to test. Each user will be assigned a company from this list at random.
# Companies the user could be part of
$Companies = @("Lab Corp", "Lab Ltd", "Env. Testing Industries", "MyLab Inc.")
A list of departments, each with a set of job roles. Each user will be assigned a random department and a role/position from within it. Once the script has finished creating users, it will run back through all created users and assign everyone in each department a manager from the same department and company.
# Departments and associated job titles to assign to users
$Departments = (
@{"Name" = "Finance & Accounting"; Positions = ("Manager", "Accountant", "Data Entry")},
@{"Name" = "Human Resources"; Positions = ("Manager", "Administrator", "Officer", "Coordinator")},
@{"Name" = "Sales"; Positions = ("Manager", "Representative", "Consultant")},
@{"Name" = "Marketing"; Positions = ("Manager", "Coordinator", "Assistant", "Specialist")},
@{"Name" = "Engineering"; Positions = ("Manager", "Engineer", "Scientist")},
@{"Name" = "Consulting"; Positions = ("Manager", "Consultant")},
@{"Name" = "IT"; Positions = ("Manager", "Engineer", "Technician")}
)
Each user will be assigned a random role from this list. Update it as required.
$employeeTypes = @("EMP", "Regular", "Contractor", "Fixed Term Regular", "Temporary", "Full-Time")
Finally, set the path for the user data. As long as the fields are the same, feel free to replace/update it.
$UsersFile = ".\FakeUserData.csv"
The script will create a user account for each user in the “FakeUserData.csv” file with the following information:
Each user created will be done so with a random company, a random department and a random role within that department.
As a final task the script will in back through all the AD accounts in the $BaseOU organizational unit and for each of the companies set in $Companies find each department and assign everyone a random manager from the same department in the same company.
If you want the environment to do something different with the SAM account names like “first.last” you will need to update line 73 to something like:
New-AdUser -SamAccountName $User.Username -Name $UserFullName -Path $UserOUPath -AccountPassword $UserPassword -Enabled $True `
to something like this:
$NewUsername = $User.givenname + "." + $User.Surname
New-AdUser -SamAccountName $NewUsername -Name $UserFullName -Path $UserOUPath -AccountPassword $UserPassword -Enabled $True `
The information stored in “FakeUserData.csv” was provided by fakenamegenerator.com and contains around 600 random users doted around Europe in the following countries: