[string]$proxydomain_1 = "@
xxx.ru";
[string]$proxydomain_2 = "@xxx.local";
[string]$powersnapin = "Coexistence-Configuration"; #Directory Sync PS-Snapin name
[string]$email = $_.SamAccountName + '$proxydomain_1'
Import-Module ActiveDirectory
Get-ADUser -Filter "*" -SearchScope Subtree -Properties ProxyAddresses, givenName, Surname, mail | foreach-object {
Write-Host "Editing user: $_.SamAccountName"
if ($_.Proxyaddresses -match $_.SamAccountName+""+$proxydomain_1)
{
Write-Host "Result: Proxy Address already exists; No action taken."
}
else
{
Set-ADUser -Identity $_.SamAccountName -Remove @{Proxyaddresses="SMTP:"+$_.SamAccountName+""+$proxydomain_2}
Set-ADUser -Identity $_.SamAccountName -Remove @{Proxyaddresses="smtp:"+$_.SamAccountName+""+$proxydomain_1}
Set-ADUser -Identity $_.SamAccountName -Add @{Proxyaddresses="SMTP:"+$_.SamAccountName+""+$proxydomain_1}
Set-ADUser -Identity $_.SamAccountName -Add @{Proxyaddresses="smtp:"+$_.SamAccountName+""+$proxydomain_2}
}
#}