Remove Disconnected/Soft Deleted Mailboxes from Exchange 2010/2013 Database

When moving mailboxes between Exchange databases the move complete with a warning. This is because Exchange server sometimes does not fully delete the mailboxes from the source database immediately upon completion of the move the source mailbox database is switched to a “soft-deleted” state. To resolve this you need to remove the disconnected or soft deleted mailboxes from the old database to free up space.

The difference between Disabled Mailboxes & Soft-Deleted Mailboxes

Disabled Mailboxes: When you delete a mailbox using the Remove-Mailbox or Disable-Mailbox cmdlet, those consider as disabled mailbox and Exchange retains those mailboxes till retention period.

Soft-Deleted Mailboxes: When we move mailbox from one database to another, the source mailbox does not get permanently deleted and mailbox switched into the soft-deleted mode.

Update the databases to show all disconnected mailboxes

Get-MailboxDatabase | Clean-MailboxDatabase

Use the below command to see a list of disconnected mailboxes in specified Exchange database:

Get-MailboxStatistics -Database "MailboxDatabase" | Where { $_.DisconnectDate -ne $null } | select DisplayName, DisconnectDate,TotalItemSize, TotalDeletedItemSize

Show all the disconnected mailboxes in specified mailbox server:

Get-MailboxStatistics -Server MBXServer | where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate | sort DisconnectDate

To see all the Disabled mailboxes in the database:

Get-MailboxStatistics –Database “MailboxDatabase″ | Where-Object {$_.DisconnectReason –eq “Disabled”}

To remove all the disabled mailboxes in database:

$Mailboxes = Get-MailboxStatistics -Database “MailboxDatabase″ | where {$_.DisconnectReason -eq “Disabled”}

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

To remove the Soft-Deleted mailboxes in database:

$Mailboxes = Get-MailboxStatistics -Database “MailboxDatabase″ | where {$_.DisconnectReason -eq “SoftDeleted”}

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

Removing Disconnected Mailboxes in Exchange 2013

You can use the below command to remove the disabled/disconnected mailboxes from a specific database:

Get-MailboxStatistics -Database “MailboxDatabaseName″ | where {$_.DisconnectReason -eq “SoftDeleted”} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled -Confirm:$False
You can use the below command to remove the soft deleted mailboxes:

Get-MailboxStatistics -Database “MailboxDatabaseName″ | where {$_.DisconnectReason -eq “Disabled”} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted -Confirm:$False