New-ComplianceSearch and Variables

Greetings, /r/powershell!

I’m running into a problem using variables with New-ComplianceSearch to create new content searches in Office 365’s Security and Compliance Center. You can connect to Security and Compliance Center per this TechNet article.aspx) if you’d like to try this yourself. You can also look at my project on GitHub for a reference as to what I’m trying to do. Today’s question deals with lines ~30 and onward.

The specific snipped I’m having trouble with is:

$searchname = Read-Host -Prompt "Enter the name you'd like to use for your content search" $subject = Read-Host -Prompt "Enter the subject of the email message you'd like to search for" New-ComplianceSearch -Name $searchname -ExchangeLocation all -ContentMatchQuery 'subject:$subject' 

In theory the search should be built looking for whatever we entered into $subject, Burt what’s actually happening is the search query is literally “subject:$subject”. This is unexpected because the single quotes aren’t literals and should be parsing the value of the variable.

What am I doing wrong?

submitted by /u/johncrist1988
[link] [comments]

Leave a Reply