Hey there again,
Now that I’ve gotten over the first post jitters, I figured I’d share a script that I created to provision AD Test Accounts. Feel free to use it or comment on improvements that can be made.
Param ( [Parameter(Mandatory=$true)][int]$TotalUsers, [Parameter(Mandatory=$true)][int]$StartingNumber, [Parameter(Mandatory=$true)][string]$User, [Parameter(Mandatory=$true)][string]$Description, [Parameter(Mandatory=$true)][string]$Manager, [Parameter(Mandatory=$true)][string]$ExpiryDate, [Parameter(Mandatory=$true)][string]$Password )#End Parameter Set $EndNumber = $StartingNumber + $TotalUsers $Range = $StartingNumber..$EndNumber #End of PowerShell Maths ForEach ($Num in $Range) { $NumID = "{0:0000}" -f $Num $userName = "$User$NumID" New-ADUser ` -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) ` -AccountExpirationDate $ExpiryDate ` -Company "Company" ` -Country "US" ` -Description ($Description)` -DisplayName $userName ` -Enabled $true ` -GivenName $userName ` -Manager $Manager ` -Name $userName ` -Path "OU=TestUsers,DC=company,DC=com" ` -SamAccountName $userName ` -Surname $userName ` -UserPrincipalName "$userName@company.com" }#End ForEach
I designed it to provision user IDs in the format of ‘UserID0000’ and gave it the ability to create a range of users. Usually we get a request to stand up 2000+ users for a given load test, and often times we’ll get an additional request to create more. This script allows me to create the initial users (say UserID0001-UserID2000), and if I get an additional request, I just input my starting number at 2001 and add the requested number of users.
I’ve actually built this as an activity for Orchestrator, but I always build the code in ISE and test it in pure PowerShell before moving it to that environment.
I admit, I used Erich Karch’s ‘Powershell: Create 1000 Test User Accounts’ as the inspiration for this script, but I wanted something that would give me more flexibility when creating users, and then be able to build it into a runbook that I can put into a service offering through SM.
Let me know what you think!