Search and Delete Messages from User Mailboxes – Exchange 2010

Hi Readers,

Today I am sharing the method to remove messages from exchange mailboxes.

Note:- Indexing should be working fine otherwise there would be issues in removing messages from mailboxes.

Create a CSV file for user mailboxes on which you want to take action:

Capture

Just logging: 

import-csv c:\tmp\Messagesubject.csv | foreach {Search-Mailbox $_.alias -SearchQuery subject:“Vikas Sukhija Schedule” -TargetMailbox “LogMailbox” -TargetFolder “Logs” -LogOnly -LogLevel Full} >c:\tmp\output.txt

Capture1

 

Move & Delete Messages:

import-csv c:\tmp\exchange2010.csv | foreach {Search-Mailbox $_.alias -SearchQuery subject:”Vikas Sukhija Schedule” -TargetMailbox “LogMailbox” -TargetFolder “Logs” -DeleteContent -force} >  c:\tmp\moveanddel.txt

Delete Messages:

import-csv c:\tmp\exchange2010.csv | foreach {Search-Mailbox $_.alias -SearchQuery subject:”Vikas Sukhija Schedule” -DeleteContent -force} > c:\temp\output.txt

Follow the next article to convert the output log to CSV so that its easy to read:

Convert Structured TEXT to CSV format

 

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

Advertisement

7 thoughts on “Search and Delete Messages from User Mailboxes – Exchange 2010

  1. Pingback: Convert Structured TEXT to CSV format | Microsoft Technologies Blog

  2. Hi Vikas, Would this script work on Exchange 2013? Can it be applied to “From” and “To” fields as well? Messages from certain domains or sent to certain domains?

      • Thanks Vikas! Here is my situation:

        On a Exchange 2013 server, I would like to search Mr Smith’s entire mailbox for all emails to and from xyz.com, and move those messages to Moved folder in JOB mailbox.
        I created a CSV file called ex13, and have the Mr Smith’s email address (jsmith@mydomain.com) in there. In PowerShell running the below command on the server would be sufficient to do this job:

        import-csv c:\tmp\ex13.csv | foreach {Search-Mailbox $_.alias -SearchQuery to:”*.xyz.com” from:”*.xyz.com”-TargetMailbox “JOB” -TargetFolder “Moved”} > c:\tmp\result.txt

        It’s ok to have “to” and “from” in the query?

        I much appreciate your help!

  3. Pingback: Convert Structured TEXT to CSV format | Tech Wizard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s