Deleting or Purging disconnected mailboxes in Exchange 2010 SP1/ SP2 or 2013

After moving around a lot of mailboxes from one database to another in Exchange 2010 SP1, i noticed that the mailboxes were not really deleted from their source database after the move.
Instead, they are marked as Disconnected Mailboxes, with a disconnected reason of “Soft-Deleted”
This is appearantly by design, according to this link

Soft-deleted mailboxes   When a mailbox is moved to a different mailbox database, Exchange doesn’t fully delete the mailbox from the source mailbox database when the move is complete. Instead, the mailbox in the source mailbox database is switched to a soft-deleted state. Like disabled mailboxes, soft-deleted mailboxes are retained in the source database either until the deleted mailbox retention period expires or until the Remove-StoreMailbox cmdlet is used to purge the mailbox.

To purge a mailbox, you can use this powershell command: Remove-StoreMailbox
Read all about it here
Problem is that when you want to delete a whole lot of boxes, you want to first get them all and them pipe the output to the Remove cmdlet.
The documentation says that to remove all SoftDeleted mailboxes from database MBD01, you run:

Get-MailboxStatistics -Database MBD01 | where {$_.DisconnectReason -eq “SoftDeleted”} | ForEach {Remove-StoreMailbox -Database $_.Database -Identity $_.MailboxGuid -MailboxState SoftDeleted}

Unfortunately, this command doesn’t work. 😦
You get the following error:
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.

This is explained on this page where it says you cannot pipe the output of one Cmdlet to another Cmdlet with the ForEach argument.

A Workaround is to declare variables. In the above command, this would be:
$Statistics = Get-MailboxStatistics -Database “MBD01” | where {$_.DisconnectReason -eq “SoftDeleted”}
$Statistics | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}

Only thing is that you will be prompted for each deletion…and no, typing A for Yes to All doesn’t work..

Advertisements

Tags: , ,

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


%d bloggers like this: