Restore Exchange Server Database Mailboxes with PowerShell

Time and again, it happens that we delete an email and sometimes, in the future it is required. While it might be a bit difficult for you to restore your personal emails which you once deleted, but, if you are using the MS Exchange Server and MS Outlook, then it is possible.

The “Powershell” can help you restore the messages or other items which you once deleted from the Exchange 2016 recovery database. Using Powershell, you can even restore Exchange Server database whenever required.

How Exchange Server 2016 Supports Recovery of Deleted Objects?

Microsoft has equipped the Exchange Server 2016 with a recovery database which can be used for restoring the information, deleted emails, messages and many other items from the mailboxes.

An organization which runs Exchange 2016 on a single server in the branch office or don’t have a database availability group can leverage the Exchange Recovery database. The recovery databases are the special mailboxes which store the entire information and can be used to obtain the deleted information or emails. But, these can only be accessed only by the admins. These databases can help to repair Exchange Server in a simple yet effective manner.

How To Recover The Deleted Emails From Recovery Database?

In order to execute the email message restoration process, a few steps are required to be followed. These steps include:

1. Build The Recovery Database

First of all, the administrator is required to create a new database object on the current Exchange Deployment and identify it as the recovery database. This new database object will hold the content that we want to be restored.

Run the following Powershell command to build the recovery database:

New-MailboxDatabase -Server EXCHANGE2016 -Name RDatabase -Recovery -EdbFilePath c:\exchange.edb -LogFolderPath c:\logs

The use of the “-Recovery” flag in the command is used to instruct the Exchange that this new database which is being created should not be used as a typical mailbox database.

2. Restore The Production Database

After this, the admin is required to restore a production database into the recently created recovery database. It will copy the data from the backup to the new recovery space.

You can use a software of any other backup process. Once the backup is complete, restore the files to the folder locations used in the PowerShell command executed above for creating the Exchange Recovery database.

3. Put Database Into Readable Condition

Now, Exchange is required to read from the mounted database, so it’s important to put it in the readable condition. So, find out the location of the recovery database and then run the following “ESEUTIL” command from the command prompt.

eseutil /r log_file_base_name /l c:\path_to_log_files /d c:\path_to_database

Before moving ahead, its vital to check the state of the database. So, run the following command from the database directory and find out the current state of the database.

eseutil /mh databasename.edb

If it says “Clean Shutdown”, you can move ahead. Next, you need to mount the database, so use the following command.

Mount-Database Name of the database

When you execute the above command with the database name that was created in the first step, it will be mounted.

4. Restoration of Deleted Mails and Information

Finally, the admin is required to run the mailbox recovery requests from bringing the data fom the mounted recovery database to the corresponding mailboxes or the different archives or mailboxes to the production side.

Once the database has mounted, you can choose any of the follwoing options to carry out the restoration.

• To restore the contents from a mailbox from the recovery database to its identical mailbox located in the production database, run following command:

New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB”

• To restore the specific folders from a particular database to a different mailbox, a corresponding mailbox or a target archive mailbox, run the following command
New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB” -IncludeFolders “Immigration Papers/*”

• To restore the contents from a recovery database on an archive database, run the following command

New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB” –TargetRootFolder “Your Restored Items”

• To restore contents from one mailbox on the recovery database to another mailbox located on the production database, run the following command:

New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB” –TargetRootFolder “Your Restored Items” -AllowLegacyDNMismatch

• Lastly, for restoring the contents from the in-built folders, attach the “Hashtag” in front and end of the folder’s name. For example #Inbox# or #Deleted Items#

What To Do When Name Conflict Arises?

Sometimes, when you are trying to restore the data, an email or some other item, an item with the same name may already exist in the destination folder. In such scenario, the admin is required to dictate that which data should be kept, the new one or the existing one, or both. You can use the “-ConflictResolutionOption” parameter in the PowerShell command to set these options.

Some examples of these commands include:

When you want to keep the source data or item

New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB” –ConflictResolutionOption KeepSourceItem

When you want to keep the lastest data or item

New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB” –ConflictResolutionOption KeepLatestItem

When you want to keep both

New-MailboxRestoreRequest -Name “AB Restore” -SourceDatabase TheRecoveryDatabase -SourceStoreMailbox “AB” -TargetMailbox “AB” –ConflictResolutionOption KeepAll

The Final Word!!

So, now if you delete some mail from your MS Outlook accidentally or intentionally, and need it back again, you need not to worry as a set of PowerShell commands can be used to restore the emails or information.

These commands are easy to execute and have a simple syntax. However, if you are looking for an easier way to restore the lost data, you can use the specialized software solutions designed specifically for this purpose.