Remove Messages from an Exchange Mailbox

Every once in a while, I get a request on how to easily remove messages from Exchange mailboxes. If you have Exchange 2010, you can use the Search-Mailbox cmdlet to remove messages. This cmdlet is most commonly used when searching mailboxes for items to recover, but can also be used to remove content with the -DeleteContent parameter.

Here is an example, that searches for a message with a specific subject and removes it:
Search-Mailbox -Identity "Byron Wright" -SearchQuery 'Subject:"Insider Info"' -DeleteContent

If you want to remove this message from all mailboxes, you would do it like this:
Get-Mailbox | -SearchQuery 'Subject:"Insider Info"' -DeleteContent

The key to using the cmdlet to remove messages is making sure that your query captures only the messages you want. I strongly suggest verifying the query results first not matter how much of a hurry you are in. The easy way is to use the -LogOnly and -LogLevel parameters. You need to define the log level as Full to capture query results.
Get-Mailbox | -SearchQuery 'Subject:"Insider Info"' -LogOnly -LogLevel Full
Note: Using multi-mailbox search requires an Exchange enterprise client access license for each mailbox searched.

Comments

Popular posts from this blog

Remove OEMDRV Drive from Dell Server

Stop SBS from Shutting Down

Expired Microsoft Exchange Server Auth Certificate