Recover a user and mailbox in Exchange online with PowerShell cmdlets

Exchange Online is a cloud-based email and calendaring solution from Microsoft that is designed to provide businesses with enterprise-class messaging capabilities. One of the key features of Exchange Online is the ability to manage users and mailboxes through PowerShell cmdlets. In this article, we will explore the steps involved in recovering a user and mailbox in Exchange Online using PowerShell cmdlets.

Before we dive into the recovery process, it is important to understand why you might need to recover a user and mailbox. There are several scenarios where this might be necessary, such as:

  • The user account has been accidentally deleted.
  • The user has left the company and their mailbox needs to be accessed by someone else.
  • The mailbox has been corrupted or damaged.

Regardless of the reason, the recovery process is relatively straightforward with the use of PowerShell cmdlets.

Step 1: Connect to Exchange Online

The first step is to connect to Exchange Online using PowerShell. This requires the Exchange Online PowerShell module to be installed on your computer. If you haven’t already done so, you can download and install the module from the Microsoft website.

Once the module is installed, open PowerShell as an administrator and run the following command:

codeConnect-ExchangeOnline -UserPrincipalName <UPN>

Replace <UPN> with the user principal name of your Exchange Online administrator account. This will establish a connection to Exchange Online.

Step 2: Identify the User and Mailbox

The next step is to identify the user and mailbox that needs to be recovered. You can do this by running the following command:

Get-Mailbox -Identity <MailboxIdentity>

Replace <MailboxIdentity> with the email address or username of the user whose mailbox needs to be recovered. This will return information about the user and their mailbox, including the mailbox GUID.

Step 3: Restore the User Account

If the user account has been accidentally deleted, it needs to be restored before the mailbox can be recovered. To restore the user account, run the following command:

Restore-MsolUser -UserPrincipalName <UPN>

Replace <UPN> with the user principal name of the deleted user account. This will restore the user account and all associated attributes, including the mailbox.

Step 4: Recover the Mailbox

Once the user account has been restored, you can recover the mailbox using the following command:

New-MailboxRestoreRequest -SourceDatabase <DatabaseName> -SourceStoreMailbox <MailboxGUID> -TargetMailbox <TargetMailbox>

Replace <DatabaseName> with the name of the database where the mailbox was located, <MailboxGUID> with the GUID of the mailbox that needs to be recovered, and <TargetMailbox> with the email address or username of the target mailbox where the recovered items will be placed.

This command will create a new mailbox restore request and begin the recovery process. You can monitor the progress of the restore request by running the following command:

Get-MailboxRestoreRequest | Get-MailboxRestoreRequestStatistics

Step 5: Verify the Recovery

Once the mailbox restore request has completed, you can verify that the mailbox has been recovered by running the following command:

Get-Mailbox -Identity <MailboxIdentity> | fl ExchangeGUID

Replace <MailboxIdentity> with the email address or username of the user whose mailbox was recovered. This will return the ExchangeGUID of the recovered mailbox, which should match the ExchangeGUID of the original mailbox.

Conclusion

Recovering a user and mailbox in Exchange Online using PowerShell cmdlets is a straightforward process that can be completed in just a few steps. By following the steps outlined in this article, you can quickly and easily recover a user and mailbox in Exchange Online