Home Windows Server Active Directory Generating Random User Names for PoC Active Directory Environments

Generating Random User Names for PoC Active Directory Environments

Reading Time: 2 minutes

In this blog post, I will cover how I create mass test accounts for my Active Directory Lab, but using real-world names, not just user01. to be able to achieve this we need to need to utilise some PowerShell and the website https://mockaroo.com/. The reason behind this is so I can then sync my test account to my HypervLAB AzureAD Tennent and then test with some Office365 User Groups. So we need firstly we need a CSV file with a FirstName, LastName setup. this can be achieved using mockaroo, which is an online website which allows you to configure tables and rows and then generate a pretty much limitless number of users.

mockaroo, will allow you to generate up to 1000 rows for free, which I think for any kind of lab environment would be huge! For my test ideally, I want 200 Users, Which will be broken down into 50 – Engineering, 50 Finance, 50 – Human Resources, 50 Internal IT.

Sample Export of the data:

PowerShell Creation Script:

# Active Directory User Import List
# Author : Simon Lee
# Date: August 2019 

# Import PowerShell Module
Import-Module -Name 'ActiveDirectory'

# Define Csv Location
$Csv = Import-Csv -Path C:\Users\administrator.hypervlab\Desktop\MOCK_DATA.csv

ForEach ( $User in $Csv ) {

# Active Directory User Variables
$DomainUPN = (Get-ADDomain).DNSRoot
$GivenName = $User.first_name
$ADGivenName = $GivenName.Substring(0,1)
$LastName = $User.last_name
$DisplayName = "$GivenName" + " " + "$LastName"
$ADAccount = $ADGivenName + $LastName
$UPNAccountID = "$ADAccount" + "@" + "$DomainUPN"
$DefaultPwd = 'Password123!!' | ConvertTo-SecureString -AsPlainText -Force

# PowerShell Creation Script
New-ADUser `
-Enabled $true `
-Name $DisplayName `
-DisplayName $DisplayName `
-GivenName $GivenName `
-Surname $LastName `
-SamAccountName $ADAccount `
-UserPrincipalName $UPNAccountID `
-Path 'OU=TestOU,OU=User Accounts,OU=HypervLAB,DC=ad,DC=hypervlab,DC=co,DC=uk' `
-AccountPassword $DefaultPwd `
-ChangePasswordAtLogon $true `



Please enter your comment!
Please enter your name here