Find and delete an email in Microsoft Purview
When you create a new compliance search, it does not automatically run the search. The commands below creates the search and then runs it.
The search is looking for an email:
- From
user@example.com
- With the subject
An email subject
- That was received between two specified dates.
$Search=New-ComplianceSearch -Name "Remove an email" -ExchangeLocation All -ContentMatchQuery ‘(From:user@example.com) AND (Subject:"An email subject") AND (Received:M/DD/YYYY..M/DD/YYYY)’
Start-ComplianceSearch -Identity $Search.Identity
To delete the results of the above search, run:
New-ComplianceSearchAction -SearchName "Remove an email" -Purge -PurgeType SoftDelete
SoftDelete
removes the email, but it is still recoverable. HardDelete
removes the email and it is not recoverable. It does not move it to the recipient's Deleted Items folder.