Powershell – The proxy address “smtp:email@domain..com” is already used by the proxy address or LegacyExchangeDN

exchangeexchange-2016powershell

when attempting to remove email addresses of MailContacts in Exchange Server 2016 using the following cmd:

Set-MailContact -Identity "bob" -EmailAddresses @{ remove="SMTP:bob@domain.com" } -EmailAddressPolicyEnabled $false

The command works in most cases, however for some email addresses it fails:

“The proxy address "SMTP:bob@domain.com" is already being used by the proxy addresses or 
LegacyExchangeDN of "domain.com/Exchange/Bob2". Please choose another 
proxy address. “

Running command:

Get-MailContact -Filter "EmailAddresses -eq 'bob@domain.com'"

Outputs the following:

Name                      Alias                                          RecipientType
----                      -----                                          -------------
bob@domain.com            bob?domain.com                                MailContact
Bob.Smith                 Bob.Smith                                     MailContact

What is the best way to remove this email address from the contacts?

Best Answer

I was able to remove the duplicate email address with this method:

 $user = Get-ADObject -LDAPFilter "(name=bob)" -Properties proxyAddresses 
 Set-ADObject $user.DistinguishedName -Remove @{proxyAddresses="SMTP:bob@domain.com"}