PowerShell Change Email Address for domain users

Create a PS1 File on the DC or connect via powerShell remote.
The script below will update users in the OU searchbase to reflect a new email address

######################################################### 
# Name: ChangeEmail.ps1
############# ##########################################
$olddomain = "OLDname.com"
$newdomain = "NewName.com"
 
Get-ADuser -Filter * -Properties givenName, Surname, EmailAddress -searchbase "OU=test2,DC=YourDomain,DC=Com" | %{
     $fname = $_.givenName
     $lname = $_.surname
     if ($_.EmailAddress -eq "$fname.$lname@$olddomain"){
         Set-ADuser -Identity $_ -EmailAddress $fname.$lname@$newdomain
	Write-Host ($_.emailAddress)
     }
}

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki
No comments yet.

Leave a Reply