Search

Create 73,000 Test AD User Accounts

Ever required the need to make lots of Domain Users? Here's a PowerShell script that does just that, more than 73,000. This can be increased by adding more First and Last names to the CSV. 73,000 test account is likely more than an entire lifetimes worth, but the script can be altered by removing all the randomizers to create actual users based on a csv list.


Download the following script (CreateTestUsers.txt) and names.csv and copy to C:\Downloads


CreateTestUsers
.txt
Download TXT • 4KB

Names
.csv
Download CSV • 3KB




Rename the 'CreateTestUsers.txt' to 'CreateTestUsers.ps1', open in PowerShell_ISE and update the domain specific entries.


Run the script and enter the number of accounts required

During testing the higher the percentage of maximum accounts the slower the script ran as struggles to make unique names.


The accounts create have their Profile and Home shares, Group Membership

Each account created has a random 14 character password that is outputted at the end to C:\Downloads\results.txt

Here's the script...


#Get OU for users

import-module activedirectory


#Get Targetted OU

$orgOU = Get-ADOrganizationalUnit "ou=Test Users,ou=Org,dc=sh,dc=loc"

$orgOU.distinguishedname


#set password length

$length = "14"


#Outs the account and password created

$results = "C:\Downloads\results.txt"


#Declares Inheritance

$inherNone = [System.Security.AccessControl.InheritanceFlags]::None

$propNone = [System.Security.AccessControl.PropagationFlags]::None

$inherCnIn = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit

$propInOn = [System.Security.AccessControl.PropagationFlags]::InheritOnly

$inherObIn = [System.Security.AccessControl.InheritanceFlags]::ObjectInherit

$propNoPr = [System.Security.AccessControl.PropagationFlags]::NoPropagateInherit


#current number of users in OU

$aduE = get-aduser -filter {samaccountname -like "*"} -SearchBase $orgOU

$existing = $aduE.count


#Import list of first and surnames

$Names = "C:\Downloads\names.csv"


#Imports and works out max possible users that can be created

$impName = Import-Csv -path $Names

$FNCT = ($impName.firstname | where {$_.trim() -ne ""}).count

$SNCT = ($impName.surname | Where {$_.trim() -ne ""}).count

$maxUN = $FNCT * $SNCT

$total = ($maxUn.ToString()) -10


do {$enter = ([int]$NOS = (read-host "Max User accounts is "$total", how many do you need"))

}

until ($nos -le $total)


$UserLists=@{}


#Randomises first and surnames

do {


$FName = ($impName.firstname | where {$_.trim() -ne ""})|sort {get-random} | select -First 1

$SName = ($impName.surname | Where {$_.trim() -ne ""}) |sort {get-random} | select -First 1

$UserIDs = $Fname + "." + $Sname

try {$UserLists.add($UserIds,$UserIDs)} catch {}

$UserIDs = $null


Write-Host $UserLists.count