ENow Blog | Exchange Center

Moving Exchange 2010 Mailboxes to Create White Space

Written by Lasse Pettersson | Jul 25, 2012 8:40:00 PM

Exchange admins are from time to time doing mailbox moves.  There could be several reasons for doing this, but the goal is often to create some white space in the mailbox databases.

By moving mailboxes to a different database you would think "holes" will be created in the source database, and that was true until you upgraded the source server to Exchange 2010 Service Pack 1. With Service Pack 1, the behavior changed to leave the data in the source database until it gets cleaned up when the mailbox retention limit is reached. (Remove-StoreMailbox additional information)

The reason for this change is that the mailbox data should be easily accessed in a catastrophic failure before having a proper backup of the target database.

But what if you really want to create some space in the database now?
You could change the mailbox retention timeout to a low number of days or even zero days. But this might not be a suitable solution, and then you will have to clean up the left-overs manually.
The referenced article above states that mailboxes are in a soft-deleted state so they can be found with this command:

Get-MailboxStatistics -Database <databasename> | where {$_.DisconnectReason -eq "SoftDeleted"}

To clean up, you use the cmdlet Remove-StoreMailbox.

To make it work, you can follow these steps:

First, save the mailboxes you want to delete in a variable:

$mbxs = Get-MailboxStatistics -Database databasename_you_want_to_clean_up | where {$_.DisconnectReason -eq “SoftDeleted”}

And then delete them:

$mbxs | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted -Confirm:$false}

This will trigger a process to clean up in the database and you can then create whitespace with this command:

Get-MailboxDatabase -Status | Sort-Object name | Format-Table Name, DatabaseSize, AvailableNewMailboxSpace

Or, for a specific database:

Get-MailboxDatabase -Identity databasename -Status | Format-Table Name, DatabaseSize, AvailableNewMailboxSpace

Remove-StoreMailbox is the same command used for purging deleted mailboxes.

$mbxs = Get-MailboxStatistics -Database databasename_you_want_to_clean_up| where {$_.DisconnectReason -eq “Disabled”}

And then:

$mbxs | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled -Confirm:$false}

After you have purged disabled or softdeleted mailboxes you should have created some whitespace for mailboxes to grow in without growing the EDB file.

Happy purging.