20 November 2012

How to remove unwanted e-mail addresses from Mail Contacts in Exchange 2010

Default e-mail address policy creates for every recipient object an address with @your.domain at the end. This is true even for Mail Contacts. So when you need an external contact (for adding to a distribution group for example), you unintentionally gave an address of your domain also. For that you need to create a new policy, to prevent such things.

The policy will be with the following parameters (the Container should also be selected, it’s not yet done on this screenshot):

image

The filtering part can be skipped with Next button. You cannot skip e-mail addresses page, so just create a new address, that is with an address, that is not present in internet (usually your local domain name will be sufficient @domain.local for example):

image

Click Next, Next and New. Now you should be done. If you create a new contact, only this address will be added. For existing contacts you need to remove previously created @your.domain addresses. For that you will need few commands in Exchange Management Shell:

$contacts = Get-MailContact -ResultSize unlimited
$contacts | foreach {$contact = $_; $email = $contact.emailaddresses; $email | foreach {if ($_.smtpaddress -like "*@your.domain") {$address = $_.smtpaddress ; Set-Mailcontact -Identity $contact.identity –forceupgrade -EmailAddresses @{Remove=$address}}}}

The script gets all MailContact objects into $contacts variable. For each member of the variable (each contact) email addresses will be extracted and verified to match for specific condition (matching your domain name). If it matched, then it will be removed from the corresponding MailContact object. ForceUpgrade is needed, if some of the objects are created in previous Exchange version.

No comments:

Post a Comment