Disconnected user's mailboxes are not immediately deleted in an Exchange Server.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to solve Exchange related errors.
Now let us look into the steps to manage disconnected mailboxes in Exchange Server.
What occurs after mailboxes are disconnected in an Exchange Server?
After deleting an Active Directory user account or Exchange mailbox, the mailbox is stored in the mailbox database for quite some time. Basically, the exchange server keeps deleting mailboxes for 30 days by default.
It is important to know that the data can be recovered from this mailbox or reassign to another user.
An Exchange mailbox is made up of two parts as listed below;
i. An Active Directory user account is meant to store all configuration data for a mailbox as well as its attributes.
ii. The actual mailbox in the Exchange mailbox database.
A deleted Exchange mailbox will be available in the database, but will not be connected to any of the AD accounts.
There are two types of deleted Exchange mailboxes as listed below;
i. "Disabled" – refers to mailboxes disabled using Disable-Mailbox or Remove-Mailbox cmdlets.
ii. "Soft Deleted" – They are the copies of the mailboxes saved in storage after moving mailbox to another mailbox database.
Common operations with deleted mailboxes
You can display the list of all available deleted mailboxes in all Exchange databases by running the command below;
Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "Disabled" } | ft DisplayName,Database,DisconnectDate,MailboxGUID
Next, locate the deleted mailboxes in one database by running the command below;
Get-MailboxStatistics –database Lon-DB1 | Where { $_.DisconnectReason -eq "Disabled" } | ft DisplayName,Database,DisconnectDate,MailboxGUID
To get the list of deleted mailboxes having SoftDeleted status, run the command as shown below;
Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "SoftDeleted" } | ft DisplayName,Database,DisconnectDate,MailboxGUID
How to Clear Exchange Databases from the Deleted Mailboxes
After a specified period of time, exchange automatically clears the deleted mailboxes from the database.
But the deleted mailboxes still occupies space in a database. In the process of migrations and removal of users, it is important to force remove the mailboxes in order to free some space in the mail databases.
With the "Remove-StoreMailbox" cmdlet, which deletes a disabled mailbox from the database permanently having specified the MailboxGUID of the deleted mailbox, you can run the command as shown below;
Remove-StoreMailbox -Database Lon-DB1 -Identity "6366636e-8eeb-4c7e-8bd3-ee2a443b071e" -MailboxState Disabled
In order to delete all disabled mailboxes in the Exchange organization, run the command below;
Get-MailboxDatabase | Get-MailboxStatistics | where {$_.DisconnectReason -eq "Disabled"} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}
To delete mailbox copies left after the migration in a specific database, run the following command;
Get-MailboxStatistics –Database Lon-DB1 | Where-Object {$_.DisconnectReason –eq “Softdeleted”} | ForEach {Remove-StoreMailbox –Database $_.database –identity $_.mailboxguid –MailboxState Softdeleted –Whatif
The process of connecting a Deleted Mailbox to a User
It is possible to connect a deleted mailbox to the same or another Active Directory account.
To connect a mailbox to the same account, run this following command;
Connect-Mailbox -Identity "TJohn" -Database Lon-DB2 -User TJohn
This can also be done from the EAC interface via Exchange "Admin Center -> Recipients -> Connect a Mailbox".
Do not forget to check and rectify SMTP aliases if applicable. Before you start using the mailbox, let the Active Directory replication process complete.
How to Restore a Deleted Mailbox to a Mailbox of Another User?
To restore the data from a deleted mailbox to an existing mailbox of another user, run the command below;
New-MailboxRestoreRequest -SourceDatabase Lon-DB2 -SourceStoreMailbox "PJohn" -TargetMailbox "Admin"
In the same way, you can restore the mailbox by its MailboxGuid. Lets say the folder name is "RestoreBox", then run the command shown below;
New-MailboxRestoreRequest -SourceDatabase Lon-DB1 -SourceStoreMailbox “2552452e-8eeb-4c7e-8bd3-ee2a545b071e” -TargetMailbox “Admin” –TargetRootFolder “RestoreBox” –AllowLegacyDNMismatch