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:

  1. Connect to Exchange Online PowerShell using your admin credentials.
  2. Run the following command to retrieve a list of deleted users:Get-MsolUser -ReturnDeletedUsers
  3. Identify the user that you want to restore and note their UserPrincipalName (UPN) value.
  4. Run the following command to restore the user:Restore-MsolUser -UserPrincipalName <UserUPN>Replace <UserUPN> with the UPN of the user you want to restore.
  5. Wait for the user to be restored. This process can take up to 24 hours.
  6. 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.
  7. 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.
  8. Wait for the mailbox restore request to complete. This process can take several hours, depending on the size of the mailbox.
  9. 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.