Delete Specific Emails from Exchange Online

In this blog post, I will show you how to delete a specific email from Exchange Online mailboxes using content search and Compliance PowerShell cmdlet.

Sometimes, you might have cases where you get a spam run and to delete a specific spam message from all mailboxes in the organization.

In my case, I will delete a spam message from a specific sender from all the mailboxes in Exchange Online.

To complete this article, you will need to have a global admin and compliance admin permissions in your Office 365 tenant.

Get Started

From the Office 365 Portal, I will click on Security & Compliance

Next, I will create a new Content search from the Search & Investigate

From the main page I will click on New search

In the search query window, I will remove the Keyword windows and click on Add conditions

In the Add conditions page I will select Sender / Author

And type the email address of the sender I want all of his emails to be deleted

 From the Locations menu I will select Exchange Online

Name the search and Save

Once the search is completed and I can see all the results I will continue to connect to Compliance Center using PowerShell.

Connect to Compliance Center using PowerShell

$UserCredential = Get-Credential

Next, I will use the cmdlet below to connect to the Service and load all the available cmdlet in the Security and Compliance Center.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

Next, I will run the cmdlet below to delete all the email found in the content search

New-complianceSearchaction -searchname "Search001" -purge -PurgeType softdelete

Conclusion

Deleting emails from Exchange Online is possible however it requires a few extra steps compared to Exchange 2016.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.