25.9 C
Wednesday, December 7, 2022

How to Clean up emails using keywords in Exchange Server

I got a request recently. Due to audit purposes, they gave me like 100 keywords and delete those emails where ever they are in the server.

Exchange 2010/2013/2016 and Office365 is much powerful and easy to do such tasks. We can use the discovery search feature to accomplish it.

Click the below Link – Make sure the Admin has appropriate Permissions


$search = '"expenses" OR "credit" OR "tax audit" OR "Payment"'

Saved the 100 Keywords to $search in the above format.

To move Content to a Specific Mailbox –

This example searches all mailboxes in your organization for messages that contain the words  in $search . The search results are copied to the administrator Mailbox in the folder Exportedmailbox

Get-Mailbox "EntermailboxName" | Search-Mailbox -SearchQuery $search -TargetMailbox "administrator" -TargetFolder "ExportedMailbox" -LogLevel Full

To Delete Content

For Specific mailbox

Get-Mailbox "EntermailboxName" | Search-Mailbox -SearchQuery $search –DeleteContent

For All mailbox

Get-Mailbox  | Search-Mailbox -SearchQuery $search –DeleteContent

To Estimate how much mails you are going to delete (Logonly Switch)

Get-Mailbox "EntermailboxName" | Search-Mailbox -SearchQuery $search -TargetMailbox "administrator" -TargetFolder "ExportedMailbox" –LogLevel Logonly

Add on –
Deleting a Subject from all mailboxes – But  Excluding a Specific Sender (Logonly Switch)

Get-mailbox -Resultsize Unlimited | search-mailbox -searchquery {Subject:"Welcome to dubai" NOT from:"administrator"} -Logonly -Targetmailbox administrator -Targetfolder Inbox

Clearing Dumpster of a Specific Mailbox – (Clearing DeletedItemsSize to 0)

search-mailbox MAILBOXNAME -SearchDumpsterOnly -DeleteContent


Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Specialized in Microsoft Azure - Office 365 / Microsoft Exchange; conducted numerous projects worldwide in designing, supporting, and implementing messaging and virtualization infrastructure for medium-sized and large enterprises. Further, I am a Cloud Architect and Technical Advisor for various start-ups.

Related Articles


Please enter your comment!
Please enter your name here

× How can I help you?