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:
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
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:
Tech Wizard
Pingback: Convert Structured TEXT to CSV format | Microsoft Technologies Blog
how do you do to make the same with a csv file, with, messagesubject, and recipients?
thanks
You need to pickup subject from csv same as I picked the Alias using $_.messagesubject
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?
yes it will work , you can also add from: in the query..
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!
Pingback: Convert Structured TEXT to CSV format | Tech Wizard