This process is designed to delete emails delivered to your own tenant in Microsoft 365.
Grant yourself the eDiscovery role:
Go to https://purview.microsoft.com/
Edit eDiscovery Manager and add your user.
Open up Powershell:
Import-Module ExchangeOnlineManagement
Connect-IPPSSession -UserPrincipalName [email protected]
Create a Compliance search (check the query)
New-ComplianceSearch -name "Search22" -ExchangeLocation all -ContentMatchQuery 'subject:"Subject of the email I want to delete"'
Trigger the search
Start-ComplianceSearch "Search22"
Check the status of the search
Get-ComplianceSearch | FL name,items,size,jobprogress,status
Once its complete, it will also display the count of emails:
Name : Search22 Items : 83 Size : 45444507 JobProgress : 100 Status : Completed
Now, it’s time to delete them
New-ComplianceSearchAction -SearchName "Search22" -Purge -PurgeType HardDelete
This will display a warning, send it
Name SearchName Action RunBy JobEndTime Status ---- ---------- ------ ----- ---------- ------ Search22_Purge Search22 Purge Helpdesk VC Starting
Monitor the purge:
Get-ComplianceSearchAction
Once the purging is done, the status will be shown as Completed.
That’s it.