You can try this:
$f = 'users1.csv'
$ou = 'OU=Test,OU=Test,OU=External Contact Records,OU=Exchange,DC=xyz,DC=com'
Import-Csv -Path $f |
ForEach-Object {
$CN = $_.Contacts # the $CN variable is never used!
Get-ADObject -Filter { (objectClass -eq "contact") -and (mail -like '*abc.com') } -SearchBase $ou -Properties targetAddress, sn, givenName, proxyAddresses, mailNickname |
ForEach-Object {
$pas = @()
foreach ($pa in $_.ProxyAddresses) {
if ($pa -cmatch '^SMTP') {
$pas += $_.Replace('abc', 'xyz')
}
else{
$pas += $_
}
}
Set-ADObject -Identity $_ -Replace @{Proxyaddresses = $pas}
}
}
I don't have an Exchange organization so I can't verify the code. You should check to make sure the proxy addresses are just a simple string because they may not be! You may also have to alter other properties of the contact object in order for them to function properly because changing the proxy addresses array may not change things like the primary SMTP proxy address.