Microsoft XDR Tutorial Guide
Microsoft XDR Tutorial Guide
XDR
Note
The Organization Management role group exists in both Exchange Online and in the
compliance portal. These are separate role groups that give different permissions. Being
a member of Organization Management in Exchange Online does not grant the required
permissions to delete email messages. If you aren't assigned the Search And Purge role
in the compliance portal (either directly or through a role group such as Organization
Management), you'll receive an error in Step 3 when you run the New-
ComplianceSearchAction cmdlet with the message "A parameter cannot be found that
matches parameter name 'Purge'".
Table of contents
Contents
Table of contents ....................................................................................................................3
1. Prerequisites ..................................................................................................................4
2. Connect to Exchange Online .........................................................................................9
3. Create Compliance Search .............................................................................................9
4. Delete mail items from all mailboxes ......................................................................... 10
5. Verify soft deleted mail items in Outlook................................................................... 12
6. Delete mail items from single Microsoft 365 mailbox ............................................... 13
7. Delete Compliance Search ........................................................................................... 14
a. Delete Compliance Search with PowerShell ............................................................... 15
b. Delete Compliance Search Action with PowerShell ................................................... 15
c. Delete Content Search in Microsoft Purview.............................................................. 15
d. Delete Content Search Export in Microsoft Purview .................................................. 18
8. Conclusion .................................................................................................................... 20
1. Prerequisites
You must assign the following permissions (Compliance Search, Search And Purge,
Preview, Export) to the admin account. This will let you search, view, export, and delete
mail items.
Check if you have set the required permissions in the Microsoft Purview compliance
portal to use the New-ComplianceSearchAction or Remove-
ComplianceSearch cmdlets.
To create a new role and assign permissions in Microsoft Purview, follow these steps:
8. Add the roles (Compliance Search, Search And Purge, Preview, Export)
9. Click Next
10. Click Choose users
Note: You need to Update the Exchange Online PowerShell module to the latest version.
Otherwise, the commands will not work.
To be able to run the PowerShell commands specified in the current article, you will
need to Connect to Exchange Online PowerShell.
Connect-ExchangeOnline
Copy
Connect-IPPSSession
Copy
Use one of the following methods to create and start a compliance search:
We suggest you follow the steps in the article How to Use the New-ComplianceSearch
PowerShell cmdlet to run a compliance search.
Once you complete the compliance search, you can proceed to the next step.
4. Delete mail items from all mailboxes
First, we will run the New-ComplianceSearch PowerShell cmdlet to create a new search.
After that, we will run the New-ComplianceSearchAction PowerShell cmdlet, to delete
mail items from the compliance search.
In our example, we want to find all the mail items that were sent to a specific
user ([email protected]) on a specific date (2024-03-15).
We will create a compliance search that will search through all the mailboxes. You need
to specify the value All in the -ExchangeLocation parameter.
Run the below PowerShell command to soft delete all the mail items of a specific
compliance search.
The PowerShell output shows the below output. It automatically creates the purge with
a name (Spam Mail_Purge) and starts.
Run the below PowerShell command to see a detailed list of the purge results.
The PowerShell output shows the below result. In our example, it deleted 44 mail items
in total and without errors.
Note: The email items are removed to the Deleted Items folder, because it’s soft-deleted.
It means the user can still find and restore or purge the email items from the Recover
Deleted Items in Outlook.
SearchName : Spam Mail
EstimateSearchRunId : 6f9c7f6b-c543-4a47-999d-08dc5107d0c5
EstimateSearchJobId : d11047fb-9725-4d8f-64ca-08dc5107ccc4
ActionVersion :
Results : Purge Type: SoftDelete; Item count: 44; Total size
895806; Details: {Location:
[email protected]; Item count: 10; Total size:
313705; Failed count: 0; ,
Location: [email protected]; Item count: 10;
Total size: 222878; Failed
count: 0; ,
Location: [email protected]; Item count: 10; Total
size: 163677; Failed count: 0;
,
Location: [email protected]; Item count: 10; Total
size: 133863; Failed count: 0;
,
Location: [email protected]; Item count: 2; Total
size: 17300; Failed count: 0; ,
Location: [email protected]; Item count: 1;
Total size: 22980; Failed
count: 0; ,
Location: [email protected]; Item count: 1; Total
size: 21403; Failed count: 0; }
Errors :
Action : Purge
ValidDuration : 00:10:00
JobId : 4c788d4e-f0e3-4f33-40e5-08dc535cba55
Name : Spam Mail_Purge
CreatedTime : 02/04/2024 21.34.50
LastModifiedTime : 02/04/2024 21.35.30
JobStartTime : 02/04/2024 21.34.50
JobEndTime : 02/04/2024 21.35.30
Description :
CreatedBy : M365info Admin
RunBy : M365info Admin
TenantId : a2ff010e-0e03-4c56-8863-2ae7f07876dd
NumBindings : 7
Status : Completed
ExchangeLocation : {All}
PublicFolderLocation :
SharePointLocation :
OneDriveLocation :
ExchangeLocationExclusion :
PublicFolderLocationExclusion :
SharePointLocationExclusion :
OneDriveLocationExclusion :
JobRunId : 7c280e70-f8c4-4c74-059f-08dc535cba5a
Retry : False
AllowNotFoundExchangeLocationsEnabled : False
JobOptions : 272
JobProgress : 100
CaseId :
CaseName :
PagingState :
Identity : 7c280e70-f8c4-4c74-059f-08dc535cba5a
ContentURL :
ResultInEOP : False
AzureBatchFrameworkEnabled : True
IsValid : True
ObjectState : New
Copy
You can also delete the mail items permanently from all the mailboxes.
Important: You can’t restore any hard deleted mail items from a Microsoft 365 mailbox,
because it will be permanently deleted.
Run the below PowerShell command to hard delete all the mail items.
1. Sign in to Outlook
2. Click Deleted Items folder
3. Click Recover Deleted items from Server
4. See the Recover Deleted Items
It will also delete the mail items in the other mailboxes. In the next step, we will explain
how to delete the mail items from a single mailbox.
We will create a new compliance search that will only search a single mailbox. You need
to specify the single mailbox value in the -ExchangeLocation parameter.
It will only search the content in the user mailbox you specified.
Note: When you create a compliance search, there is no option to change it afterward. If
you made a mistake, you need to delete the compliance search and create a new one.
To soft-delete all the mail items from a single mailbox, run the below PowerShell
command.
To hard-delete all the mail items from a single mailbox, run the below PowerShell
command.
Important: You can’t restore any hard deleted mail items from a Microsoft 365 mailbox,
because it will be permanently deleted.
New-ComplianceSearchAction -SearchName "Amanda Hansen mailbox" -Purge -PurgeType HardDelete -
Confirm:$false
Copy
It removes any compliance search with the status not started, starting, stopped,
or completed.
If you created a compliance search export or report, you can delete these results. It will
not delete the compliance search.
To remove a specific compliance search report, run the below PowerShell cmdlet.
That’s it!
Did you enjoy this article? You may also like Restore Azure AD users with Microsoft
Graph PowerShell. Don’t forget to follow us and share this article.