Quick post today. If you have an criteria of emails that you want to delete from all mailbox’s you can use Search-Mailbox to delete the message from users mailbox. For example, you get hit with a virus email that has the subject “I am a virus” from the user virussender@virus.com.
The below search goes through all mailbox’s and deletes any email with the subject “I am a virus”:
get-mailbox | Search-Mailbox -SearchQuery ‘subject:”I am a virus.” ‘ -TargetMailbox “adminmailbox” -TargetFolder “DeleteVirus” -LogLevel Full –DeleteContent |
That above command will delete the emails from the users mailbox’s and copy them to the adminmailbox in the folder DeleteVirus
The next search does it based on the sender of the email:
get-mailbox | Search-Mailbox -SearchQuery ‘from:virussender@virus.com ‘ -TargetMailbox “adminmailbox” -TargetFolder “DeleteVirus” -LogLevel Full –DeleteContent |
The above search does the same thing as the first, except this query does it based on the from address of the sender versus the subject.
If you log into the admin mailbox, you can see the results of the search and log files for it:
You can also run the same commands without the –DeleteContent switch to copy the messages to the admin mailbox for review before running the commands to delete.
Got a project that needs expert IT support?
From Linux and Microsoft Server to VMware, networking, and more, our team at CR Tech is here to help.
Get personalized support today and ensure your systems are running at peak performance or make sure that your project turns out to be a successful one!
CONTACT US NOW