Active Directory

PowerShell: Create Multiple Users in Active Directory

The following PowerShell script should be run from the Active Directory Module for Windows PowerShell. This PowerShell script will create a defined number of Test Users accounts incrementing the number on each one:

# The OU to place the user accounts in
$ou = "OU=Test Accounts,OU=User Accounts,DC=domain,DC=local"
# Number of users to create
$userCount = 2
 
$i = 1
 
While ($i -le $userCount)
{
$name = "test_user_$i"
 
New-ADUser -SamAccountName "test_user_$i" -Name "Test User $i" -DisplayName "Test User $i" -GivenName "Test" -SurName "User $i" `
-UserPrincipalName "test_user_$i@domain.local" `
-AccountPassword (ConvertTo-SecureString "pass@word1" -AsPlainText -force) `
-CannotChangePassword $true `
-Description "Test User Account $i" -Enabled $true -Path $ou -PasswordNeverExpires $true -Server "domaincontroller1"
$i = $i + 1
}
 
 
Syndicate content