Exchange Disconnected Mailbox Management

Exchange Disconnected Mailbox

As you know each Exchange Mailbox is composed of two parts an Active Directory user account and the Mailbox itself, all configuration data for a mailbox is stored in the Exchange attributes of the Active Directory user object.

A disconnected mailbox is a mailbox object that is still present the mailbox database but does not have any AD user account associated with it, there are two types of Exchange disconnected mailbox .

  • Disabled Mailboxes which are the result of disabling or removing a mailbox with cmdlets like Disable-Mailbox or Remove-Mailbox
  • Soft Deleted Mailboxes which are the result of moving mailboxes between mailbox databases

[su_note note_color=”#ffff96″ text_color=”#000000″ radius=”5″]Note: When a mailbox is moved to another mailbox database Exchange does not fully delete the mailbox object from the source database instead mark it as soft deleted and removes it when the retention period expires. [/su_note]

Display Exchange Disconnected Mailbox

Now that we have scratched the surface of what a disconnected mailbox is and how it is “created” let’s see how we can use PowerShell all Disabled Mailboxes

Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "Disabled" } | ft DisplayName,Database,DisconnectDate

The above command will display all disconnected mailboxes in all Mailbox Database, if you want to display disconnected mailboxes just for a single database you can use the following command

Get-MailboxStatistics -DataBase  | Where { $_.DisconnectReason -eq "Disabled" } | ft DisplayName,Database,DisconnectDate

If you want to display any soft deleted disconnected mailbox you would use the following command

Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "SoftDeleted" } | ft DisplayName,Database,DisconnectDate

Output for all three commands would be similar the following

DisplayName                             Database                                DisconnectDate
-----------                             --------                                --------------
Test User1                              Employees                        3/17/2014 10:22:55 AM
Test User2                              Employees                        3/17/2014 10:28:26 AM
Test User3			                    Employees                        3/18/2014 1:15:04 AM
Test User4                              Employees                        3/31/2015 9:03:31 AM
Test User5                              Employees                        6/11/2014 2:15:06 AM

As I wrote Exchange will automatically purge any disconnected mailbox from the database when the retention period has expired in a default scenario this is after 30 days.

[su_note note_color=”#ffff96″ text_color=”#000000″ radius=”5″]Note: Until the disconnected mailbox is purged from the database it will continue to count toward the total database size [/su_note]

Waiting the retention period to purge disconnected mailboxes from the database is not always desirable or even feasible that’s why it is possible to manually purge them I will describe some common scenarios you could encounter.

Purge All Exchange Disconnected Mailbox

Purging all disconnected mailboxes at once is particularly useful when a large number of users have been deleted or in all scenarios where a great number of mailboxes have been moved/migrated

Get-MailboxDatabase | Get-MailboxStatistics | where {$_.DisconnectReason -eq "Disabled"} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}

Confirm
Are you sure you want to perform this action?
Removing mailbox "5a13b560-35e4-4cd1-8705-224c166f058b" on database "Employees".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"):Y

The above command will remove all disabled mailboxes across all Exchange Mailbox databases

Purge Exchange Disconnected Mailbox in Date Range

Assuming you want to purge mailboxes disconnected in a specific date in Soft Deleted state, for example after a bulk data move, you would use a command like

$mbx=Get-MailboxDatabase | Get-MailboxStatistics | where {$_.DisconnectReason -eq "softdeleted" -and $_.DisconnectDate  -like "06/23/2015*"} 

$mbx | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}

Confirm
Are you sure you want to perform this action?
Removing mailbox "5a13b560-35e4-4cd1-8705-224c166f058b" on database "Employees".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"):Y

[su_note note_color=”#ffff96″ text_color=”#000000″ radius=”5″]Note: Using a “like” statement in the above command saves a lot of typing when using a date as specific as possible won’t affect output [/su_note]

Purge Specific Exchange Disconnected Mailbox

There are some cases where you will want to remove just a couple of mailboxes which has been disconnected, this is particularly handy when, for example, you want to purge mailboxes that have been moved to a new Mailbox database in this case you can pipe the MailboxGuid to the Remove-StoreMailbox cmdlet

First of all gather the MailboxGUID for all mailboxes you want to purge from database

DisplayName                             DisconnectDate                             MailboxGuid
-----------                             --------------                             --------------
Test User1                              3/17/2014 10:22:55 AM                      5a13b560-35e4-4cd1-8705-224c166f058b
Test User2                              3/17/2014 10:28:26 AM                      04988060-3d0b-45db-aff4-9f8b6eff75d1
Test User3			                    3/18/2014 1:15:04 AM					   101bd241-51d1-4727-a9e6-cbe2ba299863

Once you have copied the MailboxGuids of interest simply use the following two-step process

$mbx=Get-MailboxDatabase | Get-MailboxStatistics | where {$_.MailboxGuid -eq '5a13b560-35e4-4cd18705-224c166f058b'}

$mbx | ForEach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState softdeleted}


Confirm
Are you sure you want to perform this action?
Removing mailbox "5a13b560-35e4-4cd1-8705-224c166f058b" on database "Employees".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"):Y

Purge Exchange Disconnected Mailbox – Troubleshoosting

As you probably you have noticed in the above examples I use a two steps approach when purging mailboxes reason for this is to avoid the error that PowerShell would otherwise throw at me as in the example below

Get-MailboxDatabase | Get-MailboxStatistics | where {$_.MailboxGuid -eq '5a13b560-35e4-4cd1-8705-224c166f058b'}  | foreach-object {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid}

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed
Advertisements

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