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…

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!

38 Comments

  1. Isidro Bernad says:

    Hi, I have one mailbox neither disabled nor soft-deleted, the AD user does not exist and the mailbox can only be seen in powershell but not in EMC. It is not possible to remove it. I am getting crazy

    1. Rajith Jose Enchiparambil says:

      Is it a disconnected mailbox Isidro?

  2. Exchange 2010 SP3 RU7. Ran commands and they seem to run, but the result is just “>>” in the command window. I had about 10 soft deleted mailboxes after moving from 1 database to another on the same server. Do I need to develop some patience or what? Refreshing with cleandatabase command on the >> doesn’t change anything

    1. Rajith Jose Enchiparambil says:

      Hi Aaron,

      The >> specifies that the PowerShell window is waiting on more input (maybe a closing bracket is missing kind of thing). Check the command correctly & if you still have errors, paste the command and error here.

      Thanks.

  3. MACAttack says:

    I followed your instructions and everything went smoothly. However, after I ran the “Get-MailboxDatabase | Clean-MailboxDatabase” I did not see an increase in size on the drive the Mailstore resides on. Why would that be?

    1. Rajith Jose Enchiparambil says:

      You wouldn’t see, it is called whitespace. Server will start using the whitespace before it starts to use more space on your hard disk.

  4. I have moved some user’s online archives to another database but still these users online archive are shown in disconnected state mapped with first database, however users can access online archive moved to another database no issues .

    but why this message appears in disconnected state .
    do I need to clean this primary database so that users must not shown here .

    what is the syntax commands ….

  5. Good day sir,

    I have this problem after when our Active directory crashed and we need to raise a fresh AD to enable user to use exchange to read mails.

    Below is the error……

    ——————————————————–
    Microsoft Exchange Error
    ——————————————————–
    Action ‘Remove’ could not be performed on object ‘user name’.

    User Name
    Failed
    Error:
    The operation couldn’t be performed because object ‘example.com/OU/User Name’ couldn’t be found on system name.example.com’.
    ——————————————————–
    OK
    ——————————————————–
    Please what could I do to solve this problem ?

    Tommry

  6. Hi Rajith,
    i disable one user, and its purged after rentention period….
    Is there anyway to find the database name for one mailbox after its purged ??

  7. Any thoughts on stuck Disconnected mailbox? Can’t get rid of it for the life of me. One out of 200 is stuck. Can see the mailbox GUID and the Name. But every time I try to remove, stated that particular identity doesn’t exist in the particular database. It does, MMC see as disconnected and script shows up as well? Can get rid of.. Help?

    1. Rajith Jose Enchiparambil says:

      Is this 2010?

      Run Get-MailboxDatabase | Clean-MailboxDatabase and see whether Exchange refreshes the mailboxes.

  8. I’ve been looking for hours for those commands. Thanks so much you have made my day :)

    1. Rajith Jose Enchiparambil says:

      Glad to help Paul.

    1. Rajith Enchiparambil says:

      Thanks Zaf.

  9. Anonymous says:

    Thanks Eric and Alex. All commnds work perfect

  10. Hello,

    Here my on line script, which i use when i moved out all Databases.

    $Mailboxes = Get-MailboxStatistics -Database Database01 | where {$_.DisconnectReason -eq “SoftDeleted”};$count = $Mailboxes.count; $i=0 ; $Mailboxes | foreach {$i+=1;$per = $i / $count * 100; write-progress -activity ” in Progress” -status “Complete: $i ($per %)” -PercentComplete $per;Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted -Confirm:$false}

    its with Progessbar. ;-)

    Alex

    1. Sorry i mean all mailboxes

      1. Rajith Enchiparambil says:

        No problem.

    2. Rajith Enchiparambil says:

      Thanks Alex.

  11. If you had the same issue I had after the local move in Exchange 2010 SP1 and it is not a Disabled mailbox below is the command…

    [PS] C:\Windows\system32>Remove-StoreMailbox -database “Administrators”
    -identity “Alert” -MailboxState SoftDeleted

    Confirm
    Are you sure you want to perform this action?
    Removing mailbox “Alert” on database “Administrators”.
    [Y] Yes [A] Yes to All [N] No [L] No to All [?] Help (default is “Y”): y

    Now just right click on the the “Disconected Mailbox” under the “Recipiant Configuration” and choose “Refresh” and poof they are now gone.

    1. Rajith Enchiparambil says:

      Thanks Eric.

  12. jim sullivan says:

    in the second cmdlet #remove all softdeleted etc

    you are missing hte following statement. Where-Object. you only have where

    1. Rajith Enchiparambil says:

      Hi Jim,

      The cmd does have where-object. Or am I looking at the wrong one?

      Thanks.

  13. Rajith Jose Enchiparambil says:

    Thanks Reid.

  14. Thank you for posting these commands – they worked for me as listed!

  15. penetrateit says:

    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}

    1. Anonymous says:

      Perfect – Thanks!

    2. THIS!!!

      Thank you so much, penetrateit!

      1. Rajith Enchiparambil says:

        Thanks Anthony.

    3. Exactly what I was looking for!
      Thanks a million!!!

      1. Rajith Jose Enchiparambil says:

        Glad it helped you Sid.

  16. Rajith Jose Enchiparambil says:

    ;)

  17. Anonymous says:

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

  18. 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

  19. Anonymous says:

    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:Windowssystem32>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

  20. GoodThings2Life says:

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *