In the course of administering an Exchange Online instance I’m occasionally asked to locate and remove an email (or set of emails) from the entire tenant. The quickest way to do this is via PowerShell:
Connect to the Exchange Online instance, enter your credentials when prompted:
Next, Connect to the Security and Compliance Center PowerShell, entering your credentials again when prompted:
Now that you’re connected, you can create a new compliance search to locate the email(s) you wish to remove:
New-ComplianceSearch [SearchName] -ExchangeLocation 'All' -ContentMatchQuery 'from: "*@something.com"'
In the example above, I’m searching for all content across all mailboxes from a specific domain (e.g. @something.com), but you can modify the scope of the search by adjusting the location and content match query (i.e. searching by subject or just looking at specific mailboxes/folders etc.).
Once the search is created, you will need to start it:
While the search is ongoing, you can check on its status:
NOTE: You can use the “|fl“ parameter to obtain additional information on the compliance search status.
Once completed, you can use the purge the emails located by the search:
New-ComplianceSearchAction -SearchName [SearchName] -Purge -PurgeType SoftDelete