Monday, November 10, 2014

Whitespace not recovered after mailbox move

When moving a mailbox from one database to another in Exchange 2013, we all know you don't get the disk space back, we just get white space in the database for further growth. What I didn't realize for a while, is that you do not immediately get the white space either. That is because a copy of the source mailbox remains within the original database until the deleted mailbox retention period expires or until you manually remove it using the Remove-StoreMailbox command. The offending mailbox is held in a new state introduced to Exchange 2013 known as 'Soft Deleted'.

After migrating a mailbox, you can find the mailboxes that are in this condition thus:

Get-MailboxStatistics -database mydatabase| Where-Object {$_.DisconnectReason –eq ‘SoftDeleted’}

If you want to take a more holistic approach, we can have the command look at all databases by piping Get-MailboxDatabase onto the front, thus:

Get-MailboxDatabase | Get-MailboxStatistics| Where-Object {$_.DisconnectReason –eq ‘SoftDeleted’}

If you are in an emergency, you can further pipe to the Remove-StoreMailbox to remove the 'soft deleted' mailbox and get your white space back, thus:

Get-MailboxDatabase | Get-MailboxStatistics| Where-Object {$_.DisconnectReason –eq ‘SoftDeleted’}|ForEach {Remove-StoreMailbox -Database $_.Database -Identity $_.MailboxGuid -MailboxState SoftDeleted}

As a one liner, this might give you concurrent pipeline errors depending on timing. Here is the same thing as a script:

Get-MailboxDatabase|ForEach-Object `
  $DB = $_.Name
  Write-Host "Checking $DB"
  Get-MailboxStatistics -database $_.Name|foreach-object `
    If($_.DisconnectReason -eq "SoftDeleted")
            $DN = $_.DisplayName
      $ID = $_.MailboxGuid
      Write-Host "Found $DN $ID"
      Remove-StoreMailbox -Database $DB -Identity $ID -MailboxState       SoftDeleted

The following Microsoft article explains this and more:


No comments:

Post a Comment