Using Powershell to Search Mailboxes from a CSV file
Using Powershell to Search Mailboxes from a CSV file using criteria below:
a: received date (1/11/2016)
b. subject: virus test a received date and from a user called test@test.com
c. from: test@test.com
d. target mailbox: targetmailbox
e. targetfolder: targetfolder
Requirements:
a.You will need mailbox Import Export role assigned before you can do this
b. Csv file with at least alias column. Csv file in the example below is stored on C:\drive. searchoutput text file is also on C drive
The command below will search mailboxes all users in the csv file with the criteria stated above and log search results in a target folder/mailbox. Results are also stored in searchoutput text file.
Import-csv c:\Message.csv | foreach {Search-Mailbox $_.alias -SearchQuery {subject:'virustest' AND Received:"1/11/2016..1/13/2016" AND From:"test@test.com"} -TargetMailbox "targetmailbox" -TargetFolder "targetfolder" -LogOnly -LogLevel Full} >c:\searchoutput.txt
a: received date (1/11/2016)
b. subject: virus test a received date and from a user called test@test.com
c. from: test@test.com
d. target mailbox: targetmailbox
e. targetfolder: targetfolder
Requirements:
a.You will need mailbox Import Export role assigned before you can do this
b. Csv file with at least alias column. Csv file in the example below is stored on C:\drive. searchoutput text file is also on C drive
The command below will search mailboxes all users in the csv file with the criteria stated above and log search results in a target folder/mailbox. Results are also stored in searchoutput text file.
Import-csv c:\Message.csv | foreach {Search-Mailbox $_.alias -SearchQuery {subject:'virustest' AND Received:"1/11/2016..1/13/2016" AND From:"test@test.com"} -TargetMailbox "targetmailbox" -TargetFolder "targetfolder" -LogOnly -LogLevel Full} >c:\searchoutput.txt