Quantcast
Channel: Exchange Server 2013 - General Discussion forum
Viewing all articles
Browse latest Browse all 4521

search-mailbox with variables

$
0
0

Hi,

I currently have the below script that works. It pulls the users mailboxes to search from the txt file, and does the search.

get-content C:\Users\users.txt | Get-Mailbox -ResultSize unlimited | Search-Mailbox -TargetMailbox "targetmb@xyz.co.uk" -TargetFolder “TargetFolder” -SearchQuery {Subject:"SomeSubject" AND From:"firstname.lastnane@xyx.co.uk" AND sent:"19/07/2019"} –SearchDumpster -LogOnly -LogLevel Full

What I would like, and have been trying to do, is instead of pulling the users from the txt file. Is to have a variable within the script that holds the users emails, and I was also trying to use a variable for the subject, from and sent.

I was trying to get something along the lines of:

$MailboxesToSearch_Array = @("1@xyx.co.uk","2@xyx.co.uk","3@xyx.co.uk","4@xyx.co.uk")

$Subject = "SomeSubject"
$From = "firstname.lastnane@xyx.co.uk"
$Sent = "19/07/2019"

$MailboxesToSearch_Array | Get-Mailbox -ResultSize unlimited | Search-Mailbox -TargetMailbox "targetmb@xyz.co.uk" -TargetFolder “TargetFolder” -SearchQuery {Subject:"$Subject" AND From:"$From" AND sent:"$Sent"}–SearchDumpster -LogOnly -LogLevel Full

Any help would be appreciated.

Thanks



Viewing all articles
Browse latest Browse all 4521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>