Powershell Script Change Proxyaddresses

Quick tip to change proxyaddresses in Active Directory fast with csv input. This is usfull if you are running Exchange Online with dirsync. (This is an unsuported, you should have a local Exchange server for management.)

Import-Csv .\SMTPLIST.csv | ForEach-Object {

$username = $_.samaccountname
$userproxy = $_.emailaddress -split ';'
Set-ADUser -Identity $username -Add @{proxyAddresses= $userproxy}

}

your header in csv should be: samaccountname,emailaddress

To change the domain you could use:

Import-Module Servermanager
#gathering and adding aliases
$x = get-aduser -SearchBase "OU to your users" -filter * -pr * | select SAMAccountname,UserPrincipalName,proxyaddresses
foreach ($line in $x){
    foreach ($addr in $line.proxyaddresses){
                if ($addr -like "smtp:*"){
                $addr = $addr.replace("old domain","new domain")
                $addr = $addr.replace("SMTP:","")
                $addr = $addr.replace("smtp:","")
                $addr
                get-aduser -identity "$($line.samaccountname)" | set-aduser -add @{'ProxyAddresses'=@("smtp:$($addr)")}

                }
                }
               
}
#check results
$y = get-aduser -SearchBase "OU to your users" -filter * -pr * | select SAMAccountname,UserPrincipalName,proxyaddresses
foreach ($line in $y){
$line.samaccountname
    foreach ($addr in $line.proxyaddresses){
                if ($addr -like "smtp:*"){
                $addr
                }
                }
               
}

See also