Removing Duplicate Contact Items in a Exchange Mailbox

Scenario:  You have a mailbox that has hundreds of copies of their contacts in their mailbox.  For example, a user originally had 2500 contacts and now has 800,000 contacts because of the multiple copies.   Here are the steps I followed to resolve this issue.

1. Export their contacts in the users Outlook to a CSV.   In my scenario, the outlook session was locking up so I exported the PST out via Exchange Shell and then re-exported to a CSV out of Outlook. (New-MailboxExportRequest mailbox -IncludeFolders "#Contacts#" -ExcludeDumpster -FilePath \\server\share$\contacts.pst -name mailbox  -acceptlargedataloss -baditemlimit 999)

Outlook 2013:  File-->Open&Export-->Import/Export-->Export to a File-->Comma Separated Values-->Select Contacts Folder-->Save Exported File to location --> Click Finish.

2. Open Powershell, and Import the CSV created in step 1 into a Variable.
$File = Import-CSV "C:\users\username\desktop\userscontacts.csv"

3. Select the unique values for the $File, compares all columns.
$uniq = $File | Select * -unique

4. Export the unique values to a .csv file
$uniq | Export-csv "C:\users\username\desktop\userscontacts_unique.csv"

5. Delete the existing contacts in the users mailbox via Exchange Shell.  The Search-Mailbox has a 10,000 item limit. I put the command in a loop so it continues to remove all contacts at 10,000 per loop cycle.

do {
Write-Host $i
Search-Mailbox mailbox -SearchQuery kind:contacts -DeleteContent -Force
while ($i -le 81)

6. Opened Outlook 2013 and followed similar steps as step 1, except I performed the import on the unique CSV.  Note, I did have to clean up the CSV by removing the very first line as the very first line was not the column names.  In order for the CSV import to work, the first line needs to be the column names and NOT the other junk that export may have carried over.

Now the unique contacts are restored.