A safer way to deleting unwanted email content from Exchange mailboxes

A safer way to deleting unwanted email content from Exchange mailboxes

Every Exchange Admin/Engineer at some point have been asked to remove unwanted emails from user mailboxes. Use the steps below to find the message/messages, verify and delete

Step 1: Find all recipients of the email and export to csv file using the one-liner below

Get-transportserver | Get-MessageTrackingLog -Start "1/10/2016 9:00AM" -End "1/11/2016 5:00PM" -messagesubject "wormtest" -resultsize unlimited | Select-Object Timestamp,Sender, {$_.recipients}, MessageSubject | export-csv c:\allrecipients.csv

Step 2: Review the csv file from step 1 to confirm recipients. Rename $_.recipients column to Alias


Step 3: Import-csv c:\allrecipients.csv | foreach {Search-Mailbox $_.alias -SearchQuery {subject:'test' AND From:"test@test.com"} -TargetMailbox "discovery" -TargetFolder "discoverfolder" -LogLevel Full -Deletecontent -Force