It’s been some time now that I have not updated the blog with some new stuff, so let’s give a try!
In multi-organizational behavior businesses where one big enterprise has many businesses running under one ownership, and where each company shares its resources and employees information, such as names, contacts, site information, and last but not least resource availability information with other group companies. For catering this requirement often times Exchange and Active Directory administrators have to import and export mail-contacts into each their environment, which later can be represented in Microsoft Exchange Address Book (Outlook) in the form of Address List for each separate group company.
Often times we see that when this import and export process gets executed by either the central company or each of the group entity for sharing and receiving information individually, either we messes up entirely or partially with mail contacts duplication in Active Directory, which later causes mail delivery issues and in-consistency for address book.
How to fix mail contacts duplication?
To answer this question and to remove mail contacts duplication, use the below power-shell script, which can be scheduled on your Exchange Server to run automatically after each successful export against your Active Directory by the contacts-exporting-entity.
Functionality of the script:
- This script first tries to find duplicated mail contacts with multiple iterations
- After it finds the duplicated mail contacts exports the information for the administrator for record purpose, or for later deleting the mail contacts manually if administrator wants to use manual method
- Lastly if you want you can keep the “remove-mailcontact” argument at the end, it can delete the duplicated contacts automatically after the information gathering process gets complete
**Change the path of the organizational unit where you are storing all the exported mail contacts.
| $DuplicatesContacts = @() $FoundDuplicates=Get-mailcontact -OrganizationalUnit “contoso.com/contacts” -resultsize unlimited | Select PrimarySmtpAddress,DistinguishedName,Identity | sort PrimarySmtpAddress $contact = $FoundDuplicates.Count-1 for ($ZS=0;$ZS -lt $FoundDuplicates.Count;$ZS++) { if ($ZS -ne $contact){ $FIG1 = $NULL $FIG2 = $NULL $FIGREPL = $NULL $FIG1 = ($FoundDuplicates[$ZS].PrimarySmtpAddress).ToString() $FIG2 = ($FoundDuplicates[$ZS+1].PrimarySmtpAddress).ToString() $FIGREPL = ($FoundDuplicates[$ZS+1].DistinguishedName).ToString() if (($FIG1 -eq $FIG2)) { $DuplicatesContacts += $FIGREPL } $DuplicatesContacts > contactstoberemoved.txt Remove-MailContact -Identity $FIGREPL -Confirm:$false |
Note: It is recommended to give a try in test environment before you run against all production mail contacts.
I hope this would help to make your enviornment clean, cheers!
Zahir Hussain Shah