Create Random Active Directory Users

For the purpose of testing, create Active Directory users bassed on a specified list of 10 first and last names.

January 21, 2024

updated

1 min

Read Time

# responses beta

Comments
Filed

PowerShell

collection

Source Code

posted by

Brian Johnson

Brian Johnson

Source Code

 

powershell
Import-Module ActiveDirectory

$ou = "OU=Full-Time Employees,OU=Dogtoe,DC=dogtoe,DC=local"

$firstNames = @("Charles","John", "Jane", "Bob", "Alice", "Emily", "Michael", "Sarah", "David", "Jimmie")
$lastNames = @("Doe", "Smith", "Johnson", "Brown", "Williams", "Jones", "Garcia", "Miller")

$numUsers = 50

for ($i = 1; $i -le $numUsers; $i++) {

    $firstName = $firstNames | Get-Random
    $lastName = $lastNames | Get-Random

    $username = "$($firstName.ToLower()).$($lastName.ToLower())"
    $EmailAddress = "$username@dogtoe.com"
    $UserPrincipalName = "$username@dogtoe.local"

    $password = "P@ssw0rd" + (Get-Random -Minimum 100 -Maximum 999)

    New-ADUser -Name "$firstName $lastName" `
        -GivenName $firstName `
        -Surname $lastName `
        -UserPrincipalName $UserPrincipalName `
        -SamAccountName $username `
        -EmailAddress $EmailAddress `
        -AccountPassword (ConvertTo-SecureString $password -AsPlainText -Force) `
        -Enabled $true `
        -Path $ou

    Write-Host "Created user $username with password $password"
}
Soon

Tags

 

activedirectory
password
powershell
random
user
useraccount
users
windows
windowsserver

Comments Beta

 

Be the first to comment on this post!

Your personal data is secure.

Learn about how your information is collected, used, and securely stored in the Privacy Policy.