PS | Provision AD Users for Testing

< All Topics

Generate some test users in AD for testing purpose in our lab

#Create a New OU called O365
If (Get-ADOrganizationalUnit -Filter 'Name -like "O365"') {
    write-host "OU existed"
else {
    New-ADOrganizationalUnit -Name O365 

#Define OU Path and Password
$OU = (Get-ADOrganizationalUnit -Filter 'Name -like "O365"').DistinguishedName
$Password = "[email protected]!@#$"

#Provision 5 x New Users with UAT1 to UAT5
$i = 1
Do {

    $UserName = "UAT" + $i 

    New-ADUser -Name $UserName -DisplayName $UserName -UserPrincipalName $UserName'' -GivenName $UserName -Surname TEST `
        -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -Path $OU `
        -SamAccountName $UserName -ChangePasswordAtLogon $false -Enabled $true

While ($i -le 5)
Previous PS | List Inactive AD Users and Computers for Past X Days
Next PS | Working with Registry
Table of Contents