How to quickly purge Exchange 2010 mailboxes

When you create and delete a large number of test mailboxes over and over again in a pilot phase of a project, you may want to clean up the Mailbox Database before going into production.

With the clean-database powershell command you are able to cleanup the mailbox database. The command will purge all mailboxes that have an expired retention date.  When you run the command clean-mailboxdatabase in the Exchange Management Shell without setting the retention time you may receive the following event in your Application eventlog.

Event 9535: 
0 deleted mailboxes (0 kb) have been removed 
100 deleted mailboxes (2348382 kb) have been retained

By default the retention date is set to 30 days and it is set on the mailbox database. When you would like to purge mailboxes deleted for example today, you need to set the retention time on zero days. You can do this by access the Exchange Management Console or executing the command below in the Exchange Management Shell

set-mailboxdatabase -Identity "Mailbox Database" -MailboxRetention 00.00:00:00

To clean up the mailbox database you need to run the clean-mailboxdatabase command.

clean-mailboxdatabase -identity "Mailbox Database"

In the event log of the machine you will see

Event 9535: 
100 deleted mailboxes (2348382 kb) have been removed
0 deleted mailboxes (0 kb) have been retained

Next step is to compact and defrag the mailbox database, this is done by dismounting the mailbox database and use the esutil.exe utility to defrag the database.

  1. Start a command line and go to the directory where the mailbox database resides
  2. Start eseutil /d "Mailbox Database.edb"
  3. Mount the database.

When you are finished you may want to set the retention time of the deleted mailboxes back to the original setting by executing the command below:

set-mailboxdatabase -Identity "Mailbox Database" -MailboxRetention 30.00:00:00

After all of this you have a “clean” database and you can transfer your project to the next phase.

Comments

Total
0
Shares
2 comments
  1. Awesome, worked for me. Thanks.
    Just a tip, I found that some DB servers showed disconnected mailboxes while others didn’t. I recommend checking all of them.
    Eg. Get-MailboxStatistics -Server mb6 | where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate,database

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

Blank page in OWA fix for Exchange 2010

Next Post

Unable to install Exchange 2007 SP2 / SP3

Related Posts
Total
0
Share