PowerShell-Bulk Add & Remove Email Addresses

I come across a requirement from my client to change their existing Email Address to new Email Address for 200 users, and I had prepare the following PowerShell to update the ProxyAddresses in Active Directory to refresh this changes

  1. Get all users’ SamAccountName & DistinguishedName from the OU where all users created
  2. Defined the Old & New SMTP Address
  3. Loop all $User in $Users and remove thier existing Primary SMTP Address and add in thier new Primary SMTP Addresses
$Users=Get-ADUser -SearchBase "OU=Aventis,DC=Aventis,DC=local" -filter * | Select SamAccountName, DistinguishedName
$OldEmail="@Aventis.info"
$NewEmail="@AventisTech.net"

Foreach ($User in $Users) { 

$OldSMTP= 'SMTP:'+$User.SamAccountName+$OldEmail
$NewSMTP= 'SMTP:'+$User.SamAccountName+$NewEmail

Set-ADUser -Identity $user.DistinguishedName -Remove @{ProxyAddresses= $OldSMTP} -Server AVENTIS-AD01.Aventis.local
Set-ADUser -Identity $user.DistinguishedName -Add @{ProxyAddresses= $NewSMTP} -Server AVENTIS-AD01.Aventis.local

}

Leave a Comment

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

Scroll to Top