Exchange 2010: Purge/Remove disconnected mailboxes


Scan all databases for disconnected mailboxes that aren’t yet marked as disconnected in all databases and update the status of those mailboxes in the Exchange store.

Get-MailboxDatabase | Clean-MailboxDatabase

Disabled mailboxes: When a mailbox is disconnected or removed by using the Disable-Mailbox or Remove-Mailbox cmdlet, Exchange retains the deleted mailbox and the mailbox is switched to a disabled state. Disabled mailboxes are retained in the mailbox database until the deleted mailbox retention period expires or until the mailbox is permanently deleted.

Soft-deleted mailboxes : When mailboxes are moved from a Microsoft Exchange Server 2010 Service Pack 1 (SP1) database to any other database, Exchange doesn’t fully delete the mailbox from the source database upon completion of the move. Instead, the mailbox in the source mailbox database is switched to a soft-deleted state. Soft-deleted mailboxes are retained in the source database until either the deleted mailbox retention period expires or until the Remove-StoreMailbox cmdlet is used to purge the mailbox.

Source

Purge “Soft-deleted” mailboxes from specified database. (Be aware that “-Confirm” is set to “False” and you will not get any additional confirmation if you really want to purge all selected mailboxes from the database, changed to “True” if confirmation is needed.)

This command will permanently remove all disconnected mailboxes with “MailboxState” “SoftDeleted” from the database, only way to restore them after this command is with backup.

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

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

Purge “Disabled” mailboxes from specified database. (Be aware that “-Confirm” is set to “False” and you will not get any additional confirmation if you really want to purge all selected mailboxes from the database, changed to “True” if confirmation is needed.)

This command will permanently remove all disconnected mailboxes with “MailboxState” “Disabled” from the database, only way to restore them after this command is with backup.

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

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

Purge “Soft-deleted” mailboxes from specified server. (Be aware that “-Confirm” is set to “False” and you will not get any additional confirmation if you really want to purge all selected mailboxes from the database, changed to “True” if confirmation is needed.)

This command will permanently remove all disconnected mailboxes with “MailboxState” “SoftDeleted” from the server, only way to restore them after this command is with backup.

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

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

Purge “Disabled” mailboxes from specified server. (Be aware that “-Confirm” is set to “False” and you will not get any additional confirmation if you really want to purge all selected mailboxes from the database, changed to “True” if confirmation is needed.)

This command will permanently remove all disconnected mailboxes with “MailboxState” “Disabled” from the server, only way to restore them after this command is with backup.

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

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

Tested on Exchange SP1/SP2.

About these ads
This entry was posted in Exchange 2010 and tagged , , , , , . Bookmark the permalink.

2 Responses to Exchange 2010: Purge/Remove disconnected mailboxes

  1. gizmo rocko says:

    works perfectly

  2. chris says:

    Excellent worked for me

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s