Recover a user and mailbox in Exchange online with PowerShell cmdlets
To recover a user and mailbox in Exchange Online with PowerShell cmdlets, follow the steps below:
- Connect to Exchange Online PowerShell using your admin credentials.
- Run the following command to retrieve a list of deleted users:Get-MsolUser -ReturnDeletedUsers
- Identify the user that you want to restore and note their UserPrincipalName (UPN) value.
- Run the following command to restore the user:Restore-MsolUser -UserPrincipalName <UserUPN>Replace <UserUPN> with the UPN of the user you want to restore.
- Wait for the user to be restored. This process can take up to 24 hours.
- Once the user is restored, run the following command to retrieve their Exchange Online mailbox:Get-Mailbox -Identity <UserUPN>Replace <UserUPN> with the UPN of the user you restored.
- Once you have the mailbox identity, run the following command to restore the mailbox:New-MailboxRestoreRequest -Identity <MailboxIdentity> -TargetMailbox <TargetMailbox> -AllowLegacyDNMismatchReplace <MailboxIdentity> with the identity of the mailbox you want to restore, and <TargetMailbox> with the mailbox where you want to restore the deleted mailbox. The -AllowLegacyDNMismatch parameter allows you to restore the mailbox even if the legacyExchangeDN value of the restored mailbox does not match the legacyExchangeDN value of the original mailbox.
- Wait for the mailbox restore request to complete. This process can take several hours, depending on the size of the mailbox.
- Once the mailbox restore request is complete, run the following command to verify that the mailbox has been restored:Get-MailboxStatistics -Identity <TargetMailbox>Replace <TargetMailbox> with the mailbox where you restored the deleted mailbox.
That’s it! With these steps, you can easily recover a user and mailbox in Exchange Online using PowerShell cmdlets.