When a user is deleted in Microsoft 365, the mailbox is removed as well. But what if someone still needs access to the mailbox and you forgot to share it first? Or maybe you have deleted the wrong user? In these cases, we can restore the deleted mailbox in Office 365.
Mailboxes that are deleted in Office 365 are preserved for 30 days. This is also known as a soft delete and allows you to quickly and easily restore the user and mailbox. With PowerShell, we can also restore the contents of the mailbox to another mailbox.
In this article
In this article, we are going to take a look at how to restore a mailbox in Office 365 in both the Admin Center and by using PowerShell.
Restore Mailbox in Office 365
To restore a mailbox in Office 365 we first need to restore the user’s account. It’s not possible to only restore the mailbox, but after it’s restored we can turn the mailbox into a shared mailbox and remove the user account if needed.
- Open the Microsoft 365 Admin Center
- Expand Users and choose Deleted Users
- Select the delete user and click on Restore user
The user account must get a new password, leave it on Auto-generate password or create your own password. It’s recommended that the user changes their password after sign-in in, so leave that on.
- Click on Restore to restore the user
When the restore is completed, you will see the auto-generated password that is required to sign in. You can email the password or just write it down. Make sure that you assign an Office 365 license that contains Exchange Online to the user, otherwise, the mailbox won’t become active.
To access the restored mailbox we can either log in with the restored user account or convert the mailbox to a shared mailbox:
- Open the Exchange Admin Center
- Expand Recipients and click on Mailboxes
- Select the recovered mailbox
- Click on Others
- Choose Convert to shared mailbox
Read more about converting user mailboxes to shared mailboxes and setting permissions in this detailed article.
Using PowerShell to Recover Mailbox
Another option to restore a deleted mailbox in Office 365 is to use PowerShell. For this, you will need to have the PowerShell Exchange Online Module installed. We are first going to get an overview of the deleted mailboxes:
Get-Mailbox -SoftDeletedMailbox | Select UserPrincipalName, WhenSoftDeleted # Result UserPrincipalName WhenSoftDeleted ----------------- --------------- [email protected] 5-4-2023 12:28:26
To recover the deleted mailbox we can use the
Undo-SoftDeletedMailbox cmdlet. When the mailbox and user account were both deleted (normal situation) then you can recover the mailbox and user account with the following command:
Undo-SoftDeletedMailbox -SoftDeletedObject [email protected]
If the user account still exists, then we will need to recover the mailbox to a new account. We can do this by specifying the Microsoft account (Windows live id) and a new password:
# Create a password $password = ConvertTo-SecureString -String 'LazyPass!1010' -AsPlainText -Force # Recover the mailbox Undo-SoftDeletedMailbox [email protected] -WindowsLiveID [email protected] -Password $password
Restoring Mailbox Content to another Mailbox
With PowerShell, it’s also possible to restore the content of the deleted mailbox to another (existing) mailbox. This option is great when the mailbox in question isn’t too large and you only want to make the content available to another user.
The content of the deleted mailbox will be restored to the existing folders, so basically merge the mail content. Is then also better to restore the mailbox to a dedicated subfolder in the mailbox. This way a user can easily find the restored content.
Also, will we need to use the GUIDs of deleted and targeted mailboxes, so we are going to look that up first:
# Get GUID of deleted mailbox Get-Mailbox -SoftDeletedMailbox | Select-Object Name,ExchangeGUID # Get GUID of target mailbox $targetMailbox = Get-Mailbox [email protected] | Select-Object Name,ExchangeGUID
We can now restore the contents of the mailbox to the target mailbox with the following command:
# Replace <guid> with the GUID of the delete mailbox New-MailboxRestoreRequest -SourceMailbox <guid> -TargetMailbox $targetMailbox.ExchangeGUID -AllowLegacyDNMismatch -TargetRootFolder "Restored Mailbox" # Result Name TargetMailbox Status ---- ------------- ------ MailboxRestore lazyadmin Queued
You can check the progress of the restore request with the cmdlet
Get-MailboxRestorerequest. Once the restore is completed you will find a folder with the restored mailbox in the target mailbox:
We can easily restore deleted mailboxes in Office 365 due to the soft delete function, but only for 30 days. The mailbox is purged after 30 days, making it impossible to restore the contents. To prevent this you could use a third-party backup solution. This way you are not limited to the 30 days retention period.
Another option is to use litigation hold policies on mailboxes. This way you can always recover the email, but the policies should be in place before the mailbox was deleted.
I hope this article helped you with recovering the mailbox, if you have any questions, just drop a comment below.