Recovering Deleted Email Messages in Exchange Online Using PowerShell
Administrators managing Exchange Online often face the need to retrieve deleted email messages for users. Whether these items were soft-deleted by a user or hard-deleted (either by the user emptying their Deleted Items folder or through retention policies), administrators possess the capability to recover them, provided the deleted item retention period hasn't expired. This guide details the steps to locate and restore deleted messages within a user's mailbox using PowerShell.
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 ExportRole-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:
Get-Mailbox <User Mailbox> | Format-List RetainDeletedItemsForReplace
<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):
Set-Mailbox -Identity <User Mailbox> -RetainDeletedItemsFor 30Replace
<User Mailbox>with the user's email address or alias. -
To apply a 30-day retention setting to all user mailboxes in the organization:
Get-Mailbox -ResultSize unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'" | Set-Mailbox -RetainDeletedItemsFor 30Important Note:
-RetainDeletedItemsForcommands 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:
Get-Mailbox <User Mailbox> | Format-List SingleItemRecoveryEnabledReplace
<User Mailbox>with the user's email address or alias. -
To enable single-item recovery for a specific user's mailbox:
Set-Mailbox -Identity <User Mailbox> -SingleItemRecoveryEnabled $trueReplace
<User Mailbox>with the user's email address or alias. -
To disable single-item recovery for a user's mailbox:
Set-Mailbox -Identity <User Mailbox> -SingleItemRecoveryEnabled $falseDisabling 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:
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:
ReplaceGet-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"<User Mailbox>with the user's email address or alias. Adjust the-SubjectContains,-FilterStartTime, and-FilterEndTimeparameters as needed to narrow down your search.-FilterItemType IPM.Notespecifically 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:
Ensure theRestore-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"-Identity,-FilterItemType,-SubjectContains,-FilterStartTime, and-FilterEndTimeparameters match the criteria used in theGet-RecoverableItemscommand 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-RecoverableItemssupports 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-RecoverableItemscommand 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.
Comments
Post a Comment