Create Active Directory Test Users – PowerShell

A quick and simple PowerShell script that can be adjusted for your own lab environment that will create (in this example 1000) test users in Active Directory

Import-Module ActiveDirectory
 $total = 1000
 for ($userIndex=0; $userIndex -lt $total; $userIndex++) 
 { 
  $userID = "{0:0000}" -f ($userIndex + 1)
  $userName = "test.user$userID"
  Write-Host "Creating user" ($userIndex + 1) "of" $total ":" $userName
  New-ADUser `
   -AccountPassword (ConvertTo-SecureString "AAaaAAaa11!!11" -AsPlainText -Force) `
   -City "City" `
   -Company "Company" `
   -Country "" `
   -Department "Department" `
   -Description ("TEST ACCOUNT " + $userID + ": This user account does not represent a real user and is meant for test purposes only")`
   -DisplayName "Test User ($userID)" `
   -Division "Division" `
   -EmailAddress "$userName@red7lab.internal" `
    -EmployeeNumber "$userID" `
   -EmployeeID "ISED$userID" `
   -Enabled $true `
   -Fax "703-555-$userID" `
   -GivenName "Test" `
   -HomePhone "703-556-$userID" `
   -Initials "TU$userID" `
   -MobilePhone "703-557-$userID" `
   -Name "Test User ($userID)" `
   -Office "Office: $userID"`
   -OfficePhone "703-558-$userID" `
   -Organization "Organization" `
   -Path "OU=test users,OU=test objects,DC=red7lab,DC=internal" `
   -POBox "PO Box $userID"`
   -PostalCode $userID `
   -SamAccountName $userName `
   -State "Derbyshire" `
   -StreetAddress "$userID Any Street" `
   -Surname "User ($userID)" `
   -Title "Title" `
   -UserPrincipalName "$userName@red7lab.internal"
 }

 

Leave a Reply

Your email address will not be published. Required fields are marked *