The case of the 340.000 contacts in a user mailbox


One of our users suddenly had this issue, this user had over 340.000 contacts most of them duplicates. As it turns out it was a syncing issue with his mobile phone. Deleting 340.000 contacts using Outlook is a painful task, so I figured out another way to do it. Here are the steps I took:

  • Disabled the synchronization
  • Restored the user’ contacts from a recent back-up into a PST file. We are using Commvault software which has this option. You can also export the existing contacts using PowerShell.
  • Deleted the contacts using PowerShell.
  • Moved the contacts from the PST back into the users mailbox.

Step 1, 2 and 4 are quite trivial, and I assume you know how to do that. The second task is a bit more complicated, and requires some special rights within your Exchange organization. The complete PowerShell command I used to delete only the contacts from the users mailbox:

Search-Mailbox -Identity USERNAME -SearchQuery "kind:contacts" -DeleteContent

At first I encountered that the Search-Mailbox cmdlet was unavailable:

search_mailbox

As it turns out you need the “Discovery management” role within Exchange in order to use this command. Even though I am an Exchange organization administrator I added my account to this role using ECP. This fixed the missing Search-Mailbox cmdlet.

After fixing the Search-Mailbox cmdlet, I ran into another error. The parameter -DeleteContent was unavailable. In order to fix this error you need to add the “Mailbox Import Export” to the existing “Organization management” role. This finally allowed me to run this command, and here is the final result:

cmdlet_result

343311 contacts deleted, wow!

Maarten

Hi, I am Maarten and I am the owner of this weblog. I post on various IT subjects that matter in my life as an IT professional.

Recent Posts