-->

Thursday, July 8, 2021

Exchange - Finding Mismatched Email and Target Addresses

If you follow my blog, you know that I run an Exchange Resource Forest in the US, which syncs MailUsers from another Exchange environment in EMEA using MIM.

For the most part, it works...I say "most part" because it doesn't take into account user name changes as far as the TargetAddress attribute is concerned.

The problem is: if a user has a name change (which is very common when people get married or when HR misspells names - all too often), and their primary email address changes, but the TargetAddress doesn't, then your senders will get bounces from your mail server saying "recipient doesn't exist".

This is also a problem with some Hybrid Environments as well because mailboxes need to have the mail.onmicrosoft.com target in order to function...so this might help in that scenario too.

I came up with a quick PowerShell cmdlet to generate a list of all users with mismatched Email Addresses and Target Addresses.

Fire up the EMS (Exchange Management Shell) or the Active Directory Shell and  run:

Get-AdUser -Filter {Mail -like "*"} -Properties Mail,Targetaddress | Where-Object {($_.mail -and $_.targetAddress) -and ($_.mail -ne ($_.targetAddress -replace "SMTP:",""))} | select mail,@{Expression={$_.targetaddress -replace "SMTP:"};label="Target"} | Export-Csv MismatchedTargets.csv

**Note** If you want narrow down your search to a specific OU, you can add the -Searchbase switch after Get-AdUser

Now you can comb your list and correct the mismatches, and fix those bounces!

No comments:

Post a Comment