How to: Restore a mailbox in Exchange Online

Get to know how to restore a mailbox in Exchange Online.


Restores types

There are different types of restores in Exchange Online.

  • Soft-deleted mailbox restore: restores the mail to a new target mailbox from the Microsoft 365 bin
  • Restore inactive mailbox: restores the mail to a new target mailbox (mailbox and archive separate)
  • Recover inactive mailbox: recovers the entire mailbox as a new user (mailbox and archive)

How it works

When an user or mailbox gets deleted, it will land in the bin of your Microsoft 365 tenant (Soft-deleted). The object will stay there for a maximum of 30 days. Then it will go to the hard-deleted stage, if you have any retention on the mailbox, the mailbox will become an inactive mailbox. From there, you can choose to restore or recover the mailbox. In some scenarios when an user or mailbox gets deleted, the helpdesk already create it again, instead of restoring it and you need to merge the deleted and new mailbox. If the deletion is under the 30 days, you can go for a soft-deleted mailbox restore.

Restore a soft-deleted mailbox to a new mailbox

Connect to Exchange Online with PowerShell and search for the user you want to restore.

Get-Mailbox -Identity "Firstname Lastname" -SoftDeletedMailbox | Select-Object Name,ExchangeGuid

If you cannot find the user, you can do a search on a value like the PrimarySmtpAddress.

Get-Mailbox -SoftDeletedMailbox -ResultSize Unlimited | Where-Object {$_.PrimarySmtpAddress -like "domain@domain.com"} | Select-Object Name,ExchangeGuid

Copy the ExchangeGuid as “SourceMailbox”. Now we need to know the ExchangeGuid from the new TargetMailbox.

Get-Mailbox -Identity newmailbox@domain.com | Select-Object ExchangeGuid

Copy the ExchangeGuid as “TargetMailbox” and run the following command to combine those mailboxes.

New-MailboxRestoreRequest -SourceMailbox SoftDeletedMailboxGUID -TargetMailbox NewTargetMailboxGUID

If you run into an error because the LegacyExchangeDN, just add “-AllowLegacyDNMismatch” after the target mailbox guid to specifies that the operation should continue if the LegacyExchangeDN of the source physical mailbox and the target mailbox don’t match.

To check the status of the restore, you can monitor on the size of the new target mailbox.

Get-MailboxStatistics -Identity newmailbox@domain.com | Select-Object TotalItemSize

Restore an inactive mailbox

Restore the mailbox

Obtain the ExchangeGuid of the inactive mailbox.

Get-Mailbox -InactiveMailboxOnly -ResultSize Unlimited | Where-Object {$_.PrimarySmtpAddress -like "domain@domain.com"} | Select-Object Name,DistinguishedName,ExchangeGuid,PrimarySmtpAddress | Format-List

Copy the ExchangeGuid and run the following script.

$InactiveMailbox = Get-Mailbox -InactiveMailboxOnly -Identity "ExchangeGuid"

New-MailboxRestoreRequest -SourceMailbox $InactiveMailbox.DistinguishedName -TargetMailbox domain@domain.com -AllowLegacyDNMismatch

If you want that the restore land in a folder of the target mailbox run the following New-MailboxRestoreRequest instead.

New-MailboxRestoreRequest -SourceMailbox $InactiveMailbox.DistinguishedName -TargetMailbox domain@domain.com -TargetRootFolder "Inactive Mailbox" -AllowLegacyDNMismatch

Restore the archive

If you want to restore the archive also, be sure that the target mailbox has an archive in Exchange Online.

$InactiveMailbox = Get-Mailbox -InactiveMailboxOnly -Identity "ExchangeGuid"

New-MailboxRestoreRequest -SourceMailbox $InactiveMailbox.DistinguishedName -SourceIsArchive -TargetMailbox domain@domain.com -TargetIsArchive -TargetRootFolder "Inactive Mailbox Archive" -AllowLegacyDNMismatch

Recover an inactive mailbox

Obtain the ExchangeGuid of the inactive mailbox.

Get-Mailbox -InactiveMailboxOnly -ResultSize Unlimited | Where-Object {$_.PrimarySmtpAddress -like "domain@domain.com"} | Select-Object Name,DistinguishedName,ExchangeGuid,PrimarySmtpAddress | Format-List

Copy the ExchangeGuid and run the following script. This will create a new user object and will result in a total restore of the mailbox.

$InactiveMailbox = Get-Mailbox -InactiveMailboxOnly -Identity "ExchangeGuid"

New-Mailbox -InactiveMailbox $InactiveMailbox.DistinguishedName -Name userrestore -FirstName User -LastName Restore -DisplayName "User Restore" -MicrosoftOnlineServicesID user.restore@domain.com -Password (ConvertTo-SecureString -String '#PASSWORD#' -AsPlainText -Force) -ResetPasswordOnNextLogon $true

Before recovering, confirm the following bullets.

  • Be sure that the values specified for the Name and MicrosoftOnlineServicesID parameters are unique within your organization
  • If you get an error about that the domain is federetad, use domain.onmicrosoft.com as MicrosoftOnlineServicesID
  • After you recover an inactive mailbox, a new user account is also created. You have to activate this user account by assigning a license
  • The inactive mailbox became active and the mailbox will not show up in the InactiveMailbox list anymore.

Share this: