Hello,
I'm writing a script in Powershell to search messages in Exchange, and I don't know how to solve a problem that I'm encountering. I explain it.
In my script, I make the user to write an email address in a textbox. Then, I save that text into a variable. The name of the variable is $senderaddress.
Then, the script has the following line:
get-transportServer | get-messagetrackinglog -resultsize Unlimited | select-object sender, {$_.recipients},timestamp,MessageSubject,Eventid,source,Message-id | where {[string]$_.sender -like $senderaddress } | export-csv report.csv
If I put a write-host $senderaddress before that line, and the user enter, let say, test@test.com, the write-host writes test@test.com. But the report.csv is blank. If I write the following line:
get-transportServer | get-messagetrackinglog -resultsize Unlimited | select-object sender, {$_.recipients},timestamp,MessageSubject,Eventid,source,Message-id | where {[string]$_.sender -like "test@test.com" } | export-csv report.csv
when I run the script, the report.csv has the list of mails sent by test@test.com
I have tried to put the " in the variable, with the following sentence: $senderaddress = """" + $senderaddress + """", and the write-host $senderaddress throws "test@test.com" with the quotation marks, but still, the original sentence writes a blank report.csv.
What am I doing wrong? Why the sentence works if I put the value of $senderaddress hardcoded, and doesn't works if I pass as a variable?
Thanks.