Recently i had to delete some emails from a few user mailboxes. Now i had the choice i could either log in to each mailbox and delete the emails manually or use the Exchange Management Shell. Now i had in excess of 100 mailboxes to process so i chose to use the exchange shell to remove the emails
The syntax for the exchange management shell is as follows:
Search-Mailbox -Identity “username or alias” -SearchQuery ‘Subject:” Your query “‘ -DeleteContent
This is good for one mailbox however this is still Powershell so i can pipe the output of Get-Mailbox as follows to check and delete from every mailbox
Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery ‘Subject:”Your query”‘ –DeleteContent
As a additional note you can use the following additional syntax to make copies of the mail found by the search
-TargetMailbox “Search Mailbox Name” -TargetFolder “Your Target folder”