Powershell Commands to Restore Exchange 2013 Deleted Mailbox

What is a disconnected mailbox? A disconnected mailbox is what happens when a mailbox is deleted. When an administrator deleted a mailbox it’s not physically deleted. Exchange Server will put the mailbox in the disconnected mailbox location. It’s like the recycle bin for your Exchange Server mailboxes with the difference that by a default policy, any mailbox older than 30 days in the disconnected mailbox section will be automatically permanently deleted. This retention period can be changed by right-clicking on the Mailbox Store and opening the properties. On the Limits tab, you can change the “Keep Deleted Mailboxes for (days)” with the number of desired days.

The scope of this article is to go through the process to restore a disconnected mailbox via PowerShell. For this purpose we need to use the Connect-Mailbox PowerShell cmdlet.

First we need to check the disconnected mailbox we have available in our Exchange Server. This can be checked via the Exchange Admin Center by opening Recipients, clicking on the … button and clicking on Connect a mailbox.

Here you will see a list of the disconnected mailboxes as below

To see this in PowerShell you would need to open the Exchange Management Shell and use the Get-Mailboxdatabase combined with Get-MailboxStatistics PowerShell cmdlets to get a list of all the disconnected mailbox in your setup through all the mailbox databases
The command is as below

The result should be something like this.

If you would like to get the disconnected mailbox for a specific Mailbox Database you would need to update the command as below to specify the name of the database.

An issue that you might encounter is that although there are disconnected mailboxes, when running the command it will return no mailboxes. If you have configured an unmounted recovery mailbox database, the PowerShell will not return mailboxes. The problem is that if you run it, no issues occur. The recovery database must be removed prior to checking this. When the recovery database was removed, the mailboxes will show.

To connect a disconnected mailbox which was deleted or disabled you would need to use the PowerShell cmdlet Connect-Mailbox. This can be used to reconnect a user mailbox, linked, room or equipment.

Below is an example of the command

The –Identity is the Display Name of the disconnected mailbox which can be retrieved from the previous command to get the disconnected mailboxes. The –Database is the database of where the mailbox resided. The –User and the –Alias are the Display Name and the Email Alias of the User in your Active Directory. The Alias parameter is not an obligatory parameter as if you leave it blank, the username is taken in account to create the email address of the reconnected mailbox.

After you have built up the command and executed you will get no message acknowledging the success of the process.

Then if you refresh the view in your Exchange Admin Center under the recipients node, you will see the newly restored mailbox attached to the Active Directory user you specified in the command

A note to consider when doing this is that the Active Directory user has been created beforehand. You will not be able to connect a mailbox without an existing user. It can be a new user which is not associated with the name but it must exist as if you run the command it will just give you an error that the user does not exist.

Another thing to consider is that when connecting to a disconnected mailbox to a user the user cannot be disabled. If you run the command trying to connect a mailbox and the user is not enabled, you will get an error stating that the User’s Active Directory account must be logon-enabled.

If you would want to connect a linked mailbox, you would need to use the same command but a little bit different.

In the example below the LinkedDomainController is the computer name of the domain controller and the LinkedMasterAccount is the user which should be given the mailbox to.

To connect a Shared Mailbox you would need to use the same command as to connect a normal mailbox but adding the –Shared parameter at the end as the example below

Once the mailbox is connected you will be able to use it and export it using the New-MailboxExportRequest cmdlet. So the steps to recover a deleted mailbox are:

  • Having an enabled AD user to attach it to
  • Run the Connect-Mailbox command
  • Export to PST using New-MailboxExportRequest

Using an application like Stellar Repair for Exchange you will be able to recover deleted mailbox from all Exchange Server versions. When mailbox database is corrupted or you are restoring an old Exchange Server backup and all you have is the EDB file? An EDB file is proprietary of Microsoft and off the shelf you cannot mount it except if you setup the same infrastructure and perform a whole EDB restore which is a lengthy process. Stellar Repair for Exchange browse through an EDB file with ease, create a filter to search for a specific email/s export to PST and other format. You are also able to export directly to a live Exchange Server or Office 365 Tenant. All this is done with just a few clicks, hassle free.