PowerShell to Provision User Account in AD

Refer to the steps on how to use powershell to provision user account in AD for lab testing purpose

#Create a New OU
$OU = "UAT"
New-ADOrganizationalUnit -Name $OU

#Parameter for New Users
$Path = Get-ADOrganizationalUnit -Filter {Name -eq $OU} 
$User = "UAT"
$UPN = "aventislab.com"
$LastName = "TEST"
$Password = "P@ssw0rd!@#$"

#To create 10 UAT Users for Testing Purpose in UAT OU 
for ($i=1; $i -lt 11; $i++) {

    $UserName = $User + $i 

    New-ADUser -Name $Username -DisplayName $Username -UserPrincipalName $UserName"@Aventislab.com" `
    -GivenName $Username -Surname $LastName -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) `
    -Path $Path.DistinguishedName -SamAccountName $Username -ChangePasswordAtLogon $false -PasswordNeverExpires $true -Enabled $true

#Connect to Exchange 2016 in PowerShell ISE
. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto

Get-ADUser -SearchBase $Path -Filter * | % {

    Enable-Mailbox -Identity $_.Name -Database LOCAL 


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top