Karchworld Identity

Adventures in identity management, federation, directory services, software engineering, computer science...

Powershell: Create 1000 Test User Accounts

Powershell: Create 1000 Test User Accounts

Rate This
  • Comments 3

For those looking for populate a test domain -- oooh with say a 1000 users with distinct user attribute values -- here is a script that I think will do you just fine: 

 


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 "US" `
   -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@karchworld.local" `
    -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=Users,,DC=KARCHWORLD,DC=LOCAL" `
   -POBox "PO Box $userID"`
   -PostalCode $userID `
   -SamAccountName $userName `
   -State "VA - Virginia" `
   -StreetAddress "$userID Any Street" `
   -Surname "User ($userID)" `
   -Title "Title" `
   -UserPrincipalName "$userName@karchworld.local"
 }

Comments
  • Hi,

    what about if I want to create 100.000 users or even more? Your script than runs on an error. Any idea how to do that for testing purposes?

    Thanks!

    Peter

  • Small typo in:

    -Path "OU=Users,,DC=KARCHWORLD,DC=LOCAL"

    There's an extra comma after Users

    Thanks for the script, just helped me in a lab :)

  • Should also read -Path "CN=Users,DC=yourdomain,DC=local"

Page 1 of 1 (3 items)
Leave a Comment
  • Please add 7 and 2 and type the answer here:
  • Post