Hossain Labs

Home / Blog / Exchange Online

Recovering Deleted Email Messages in Exchange Online Using PowerShell

By Md Sajid Hossain28 April 2025Updated 1 December 20264 min read

Start with the mailbox, the approximate deletion time, and a detail that identifies the message. Use those details to narrow the search before restoring anything.

Before You Begin:

Ensure the following prerequisites are met before proceeding with the recovery process:

  • Mailbox Import Export Role: You must be assigned the Mailbox Import Export Role-Based Access Control (RBAC) role to perform these actions.

  • Retention Policy for Deleted Items: By default, Exchange Online retains permanently deleted items for 14 days. This duration can be adjusted up to a maximum of 30 days using PowerShell.

    • To check the current retention period for a specific mailbox:

      PowerShell
      Get-Mailbox <User Mailbox> | Format-List RetainDeletedItemsFor

      Replace <User Mailbox> with the user's email address or alias.

    • To set a specific retention period for a user's mailbox (e.g., 30 days):

      PowerShell
      Set-Mailbox -Identity <User Mailbox> -RetainDeletedItemsFor 30

      Replace <User Mailbox> with the user's email address or alias.

    • To apply a 30-day retention setting to all user mailboxes in the organization:

      PowerShell
      Get-Mailbox -ResultSize unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'" | Set-Mailbox -RetainDeletedItemsFor 30

      Important Note: -RetainDeletedItemsFor commands only apply to existing mailboxes and won't automatically affect new mailboxes created in the future. To manage this setting for new mailboxes, configure a mailbox plan with a retention policy that suits your requirements.

  • Enable Single Item Recovery: Single item recovery must be enabled for a mailbox before the item you intend to recover is deleted. By default, this feature is enabled for new mailboxes.

    • To verify if single-item recovery is enabled for a mailbox:

      PowerShell
      Get-Mailbox <User Mailbox> | Format-List SingleItemRecoveryEnabled

      Replace <User Mailbox> with the user's email address or alias.

    • To enable single-item recovery for a specific user's mailbox:

      PowerShell
      Set-Mailbox -Identity <User Mailbox> -SingleItemRecoveryEnabled $true

      Replace <User Mailbox> with the user's email address or alias.

    • To disable single-item recovery for a user's mailbox:

      PowerShell
      Set-Mailbox -Identity <User Mailbox> -SingleItemRecoveryEnabled $false

      Disabling single-item recovery might be necessary before permanently deleting content from a mailbox.

    • To enable single-item recovery for all user mailboxes in the organization:

      PowerShell
      Get-Mailbox -ResultSize unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'" | Set-Mailbox -SingleItemRecoveryEnabled $true

Managing Deleted Items:

Follow these steps to search for and recover deleted email messages:

Step 1: Connect to Exchange Online PowerShell

Refer to the official Microsoft documentation for detailed instructions on how to establish a connection to Exchange Online PowerShell. Typically, this involves installing the ExchangeOnlineManagement module and using the Connect-ExchangeOnline cmdlet with your administrator credentials.

Step 2: Search for Recoverable Items

The Get-RecoverableItems cmdlet allows you to search for deleted items within a user's Recoverable Items folder. This folder contains items that have been soft-deleted or hard-deleted but are still within the retention period.

  • To retrieve all available recoverable deleted messages with a specific subject within a defined date and time range for a specific mailbox:
    PowerShell
    Get-RecoverableItems -Identity <User Mailbox> -SubjectContains "Message subject" -FilterItemType IPM.Note -FilterStartTime "1/1/2023 12:00:00 AM" -FilterEndTime "2/1/2023 11:59:59 PM"
    Replace <User Mailbox> with the user's email address or alias. Adjust the -SubjectContains, -FilterStartTime, and -FilterEndTime parameters as needed to narrow down your search. -FilterItemType IPM.Note specifically targets email messages.

Step 3: Restore Recovered Items

Once you have identified the deleted messages using Get-RecoverableItems, you can restore them directly to the user's mailbox using the Restore-RecoverableItems cmdlet.

  • To restore the recoverable items found in the previous step (matching the subject and date/time range) back to the user's mailbox:
    PowerShell
    Restore-RecoverableItems -Identity <User Mailbox> -FilterItemType IPM.Note -SubjectContains "Message subject" -FilterStartTime "1/1/2023 12:00:00 AM" -FilterEndTime "2/1/2023 11:59:59 PM"
    Ensure the -Identity, -FilterItemType, -SubjectContains, -FilterStartTime, and -FilterEndTime parameters match the criteria used in the Get-RecoverableItems command to restore the correct items.

Additional Considerations:

  • Mailboxes on Hold: If a mailbox is subject to an In-Place Hold or Litigation Hold, messages within the Recoverable Items folder are preserved until the hold duration expires or is removed. An unlimited hold will retain items indefinitely until the hold is modified.

  • Filtering Options: Beyond subject and date range, Get-RecoverableItems supports other filtering parameters, such as filtering by sender or recipient, to refine your search.

  • Performance: When dealing with a large number of deleted items, the Get-RecoverableItems command might take some time to execute.

  • Audit Logging: Reviewing Exchange audit logs can provide valuable insights into when and by whom items were deleted, aiding in the recovery process.

By following these steps, Exchange Online administrators can effectively leverage PowerShell to search for and recover deleted email messages for their users, ensuring data retention policies are adhered to and minimizing potential data loss.

References

Md Sajid Hossain

Modern Workplace & Data Security Engineer in Dhaka. Microsoft 365, Purview, Entra ID and Exchange, from real tenants and support cases.

Work with me · LinkedIn