Let’s talk about how to delete the emails with spesific words in subject from a user’s mailbox.
As we can see, there are a lot of emails with the same subject “Message Center Major Change Update Notification”, they are useful, but after I read them, I would like to delete them all.
It’s inconvenient to delete them one by one, if there is a way to delete them just by a command , it would be better.
Of cause there is a way, let’s get started.
Before we get move further, please ensure that you has delegeted as Mailbox Search or Mailbox Import Export Role. I have both of the roles.
Connect to Exchange Online Management Shell first.
Okay, a warning, but doesn’t metter.
This goal can be achieved by using the cmdlet Search-Mailbox, for my example, if I would like to delete all the emails with the keywords “Message Center Major Change Update Notification” in the subject, I just need to run the command as below:
Search-Mailbox -Identity tianbaob -TargetMailbox dabiaoz -TargetFolder Inbox -SearchQuery “Message Center Major Change Update Notification” -DeleteContent
This would delete all the emails with the keywords I specified in tianbaob’s (me) mailbox, and the mailbox search result will send to dabiaoz’s Inbox.
Let check for the result:
Brilliant! we did it, cheers!