Wednesday, 22 September 2010

Purge Disconnected Or Soft-Deleted Mailboxes Using Remove-StoreMailbox In Exchange 2010 SP1…

Purging disconnected mailboxes isn’t that straightforward in Exchange 2007 & 2010. You have to run multiple commands to purge the disconnected mailboxes, read more here. The option to remove disconnected mailboxes is still not available in 2010 SP1 Console.

Things have changed slightly in 2010 SP1, atleast in the Exchange Shell world. A new command “Remove-StoreMailbox” has been introduced to purge disconnected or soft-deleted mailboxes (new in 2010 SP1).

Info - When mailboxes are moved from a 2010 SP1 database to any other database, Exchange doesn't fully delete the mailbox from the source database immediately upon completion of the move. Instead, the mailbox in the source mailbox database is switched to a “soft-deleted” state, known as soft-deleted mailboxes.

Let me explain the command based on my environment. I am disabling the mailbox of Chakka Rajith.

Disable Chakka Mailbox

The mailbox goes into a disconnected state and is visible in “Disconnected Mailboxes” node in the console.

Disconnected mailboxes

As is the case in Exchange 2007 & 2010 RTM, there is no button to remove the disconnected mailboxes in the 2010 SP1 console. We can use the “Remove-StoreMailbox” command to remove it in 2010 SP1. To remove Chakka’s mailbox permanently, I ran the following command

Remove-StoreMailbox –database “DB2” –identity “Chakka Rajith” –MailboxState Disabled

One thing to note is that that “database” parameter is required.

Remove chakka mailbox

Once the command was run, I had to run Get-MailboxDatabase | Clean-MailboxDatabase to refresh my console view. And for sure, the mailbox got deleted permanently.

Disconnected mailboxes

If you want to remove all disconnected mailboxes from a database, run the following command

Get-MailboxStatistics –Database “dbname” | Where-Object {$_.DisconnectReason –eq “Disabled”} | ForEach {Remove-StoreMailbox –Database $_.database –identity $_.mailboxguid –MailboxState Disabled

If you want to remove all soft-deleted mailboxes from a database, run the following command

Get-MailboxStatistics –Database “dbname” | Where-Object {$_.DisconnectReason –eq “Softdeleted”} | ForEach {Remove-StoreMailbox –Database $_.database –identity $_.mailboxguid –MailboxState Softdeleted

We can purge disconnected mailboxes using a one-liner in 2010 SP1. That’s an improvement!


8 comments:

GoodThings2Life said...

I tried to run your piped commands to remove all disconnected mailboxes, but I received the following error:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.

I am running Exchange 2010 SP1 with Rollup 2. Any thoughts?

Anonymous said...

Thnx for your post.

But i have a problem while purge disconnected mailbox on exhcnage 2010 SP1

getting mentioned error on power shell:-


[PS] C:\Windows\system32>Get-DisconnectedMailbox "LOGS" | Remove-DisconnectedMailbox -Confirm:$false
The term 'Get-DisconnectedMailbox' is not recognized as the name of a cmdlet, function, script file, or operable
m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:24
+ Get-DisconnectedMailbox <<<< "LOGS" | Remove-DisconnectedMailbox -Confirm:$false
+ CategoryInfo : ObjectNotFound: (Get-DisconnectedMailbox:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Regards
Lalit

Rajith Jose Enchiparambil said...

Hi Lalit,

The command in 2010 SP1 is different. Check my article http://www.howexchangeworks.com/2010/09/purge-disconnected-or-soft-deleted.html

Unknown said...

Thnx Rahith for your feedback,

Above command not working in Exchange 2010 Sp1
but i have deleted all the disconnected mailbox.

i did some changes in DB settings & run mentioned command in win shell.

clean-mailbox -identity "DBNAME"

Please update full command in a single line

Regards
Lalit

Anonymous said...

Wow I think without Google Microsoft would fall hard because of the complexity they added to Exchange

penetrateit said...

Proper way of deleting/purging disconnected mailboxes on Exchange SP1.

#Update the databases to show all disconnected mailboxes

Get-MailboxDatabase | Clean-MailboxDatabase

#List all disconnected mailboxes in a database and display DisconnectReason if its SoftDeleted or Disabled

Get-MailboxStatistics -Database "Database-01" | Where-Object {$_.DisconnectDate -Notlike $NULL} | Format-Table DisplayName, DisconnectDate, MailboxGuid, DisconnectReason –Wrap

#Remove all SoftDeleted disconnected mailboxes from a Database

$Mailboxes = Get-MailboxStatistics -Database "Database-01" | where {$_.DisconnectReason -eq “SoftDeleted”}
$Mailboxes | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}

#Remove all Disabled disconnected mailboxes from a Database

$Mailboxes = Get-MailboxStatistics –Database “Database-01” | Where-Object {$_.DisconnectReason –eq “Disabled”}
$Mailboxes | ForEach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled}

Reid said...

Thank you for posting these commands - they worked for me as listed!

Rajith Jose Enchiparambil said...

Thanks Reid.

Post a Comment