O-Xchange Notes from the Field!

Thursday, January 21, 2016

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

1 comment:

  1. I needed a universal file viewer. Working with
    Shutterstock and Fotolia video stok, I have accumulated too many tasks associated with open .csv file https://wikiext.com/csv and honestly,
    I don't really want to download more and more program for every file extension. This is cumbersome, unjustified. And besides, there are more rational solutions, I would recommend using them.

    ReplyDelete