Restore Mailbox In Exchange Using PowerShell

How To Restore Mailbox In Exchange Using PowerShell

In MS Exchange, when a mailbox is deleted, it isn’t immediately removed from the server. The mailbox disconnects from the user account but remains in the mailbox database on the server. The deleted mailbox remains on the server until the retention period expires.

By default, this retention period is 30 days. After the retention period expires, the mailbox is permanently deleted from the database. Also, when a mailbox is deleted, either accidentally or deliberately, the user account associated with the mailbox is deleted from the AD (Active Directory).

However, one can restore the deleted mailbox before it is purged or removed permanently from the Exchange database file (EDB). You can use either the Exchange Admin Center (EAC) or PowerShell commands in Exchange Management Shell (EMS). However, EAC provides limited options when it comes to restoring mailbox in Exchange and does not work every time.

Thus, in this guide, we explained the process to restore mailbox in Exchange by using PowerShell commands in EMS. 

Steps to Restore Mailbox in Exchange using PowerShell

In Exchange, you can restore a deleted mailbox to an Active Directory a new or existing user account, or export the content of the deleted mailbox to an existing mailbox in the database (this can’t be done via EAC). The steps are as follow,

Step 1: Check Deleted Mailbox Status

Before you proceed any further, first check if the deleted mailbox still exists in the database. For this, open EMS as administrator and then execute the following command,

Get-MailboxDatabase | foreach {Get-MailboxStatistics -Database $_.name} | where {$_.DisplayName -eq “<display name>”} | Format-List DisplayName,Database,DisconnectReason

If the output displays DisconnectReason as Disabled, it indicates the mailbox is still in the database and can be restored. However, if the command output doesn’t display anything, it indicates that the mailbox is permanently deleted or purged from the database.

Step 2: Assign Required Permissions

Before you can execute any PowerShell command in EMS to restore the mailbox, the user account you are using should have the required permissions assigned. In case of insufficient permissions, the mailbox restore will fail. To check and assign required permissions, check out the “Recipient Provisioning Permissions” section.

Step 3: Create a New User Account

As mentioned earlier, when a mailbox is deleted, the associated user account is also deleted from the AD. Thus, if you want to restore the mailbox to the original user account, you need to recreate the user account in Active Directory. Otherwise, you can also choose an existing user which isn’t mail-enabled in the AD and restore content from the deleted mailbox to the existing user’s mailbox.

Step 4: Connect Deleted Mailbox to User Account

After creating or determining the user account, you can go ahead and connect the deleted mailbox to the user’s account via Connect-Mailbox Exchange Management Shell cmdlet.

IMPORTANT NOTE: While connecting the mailbox, you must specify the type of mailbox

For instance, the following command connects the deleted mailbox to a user account. The Identity parameter is used to specify the deleted mailbox database (DB01) and the User parameter to specify the AD user (Sammy TheShark) that you want to connect to a deleted mailbox.

Connect-Mailbox -Identity “Sammy” -Database DB01 -User “Sammy TheShark” -Alias sam

Step 5: Restore Deleted Mailbox to An Existing Mailbox

You may also restore the deleted mailbox in Exchange to an existing mailbox by using the New-MailboxRestoreRequest PowerShell cmdlet in EMS. In this process, the content of the deleted mailbox is copied to an existing mailbox in the database which is specified with the TargetMailbox parameter.

However, to restore mailbox content, you must know the display name, legacy DN or mailbox GUID of the deleted mailbox. To know these details, type the following command in the EMS,

$dbs = Get-MailboxDatabase

$dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq “Disabled”} | Format-Table DisplayName,MailboxGuid,Database,DisconnectDate

This displays the DisplayName, mailboxGUID, and Legacy DN of all disabled and deleted mailboxes in your organization. Find and copy the details of the deleted mailbox that you want to restore. 

Then execute the following command in EMS to restore the deleted mailbox to an existing mailbox on the server.

New-MailboxRestoreRequest -SourceStoreMailbox hg345se7-79a2-4f94-4549-9jh5s47jd372b -SourceDatabase DB01 -TargetMailbox “Tony Stark” -AllowLegacyDNMismatch

NOTE: AllowLegacyDNMismatch is used to restore the source mailbox to a different mailbox with a different legacy DN

Verify if these steps worked

After executing the Powershell commands for restoring the mailbox in Exchange, verify if it worked and successfully connected the mailbox to a user account.

Get-User <Identity>

Verify If It Worked

To verify if this worked and you have successfully restored the mailbox in Exchange using PowerShell, run Get-MailboxRestoreRequest cmdlet in EMS. The output will display either Queued, InProgress, or Completed status. Once the process completes, successfully, you can open and access the target mailbox to access the deleted mailbox content.

What If It Didn’t Work?

In some cases, a user may not able to execute these steps successfully or may experience issues, such as the status of the restore mailbox command is stuck InProgress. Also, these manual steps require technical skills and careful execution to avoid any data loss or further problems.

However, if the steps didn’t work for you, you can install an Exchange recovery software, such as Stellar repair for Exchange to recover deleted mailbox in PST format. Once recovered, you can import the mailbox content in the PST file to any mailbox in the Exchange database with a few clicks. The software also allows you to directly export the recovered mailbox and its content to an existing user on the server.

It’s easy to use, convenient, doesn’t require additional permissions, and lets any user recover and restore deleted mailbox in Exchange when PowerShell command or EAC fails.

You can download the software for free and try it yourself. For any help, you can always reach us via comment below.

Leave a Comment