Remove mails from Exchange online user mailbox


Remove the emails from Exchange online user mailbox

When SPAM emails have been delivered to user mailbox, admin must remove the emails from mailboxes by determining recipients of the spam email and deleting them from recipient mailbox. Or in some instances confidential emails shared internally to the wrong user/recipient. For a precaution, I would suggest you have one shared mailbox to be created for such activities and save the deleted emails to this shared mailbox.
Get-MessageTrace -SenderAddress "sender@spam.com" -StartDate “start date in mm/dd/yyyy” -enddate “end date in mm/dd/yyyy” -Pagesize 5000 | Export-csv “output.csv"
  • Filter the columns based on the subject and copy the recipient field to another csv file which would be the input for the future commands. Ensure the column name is set to “name”.
  • Run a test batch with the below powershell to identify the query result and the estimated number of emails. The output of the estimates is saved to .txt file. Analyse the output and adjust the query if required.
Import-csv “input.csv" | foreach {Search-Mailbox -Identity $_.name -SearchQuery 'Subject:"Subject of the spam mail" AND From:"sender@spam.com”' -EstimateResultOnly} >> estimate.txt
  • Execute the below command to remove the mails from recipient mails and save them to the backup shared mailbox.
Import-csv "input.csv" | foreach {Search-Mailbox -Identity $_.name -SearchQuery 'Subject:"Subject of the spam mail" AND From:"sender@spam.com”'  -DeleteContent -Force -LogLevel Full -TargetMailbox "backupsharedmailbox@domain.com" -TargetFolder "desired folder name"} >> outputfile.txt


Comments

Post a Comment

Please add comments and feedback

Popular posts from this blog

Clearing Exchange online mailbox purge, dumpster folder

create AD contacts, Bulk create AD contacts - Active Directory PowerShell

Add description to AD contact and bulk add description for contacts - Active Directory PowerShell