How can I adjust my PowerShell command to make variables work properly?

0
0
Asked By CoolCoder42 On

I'm trying to use a param block in my PowerShell script to populate some variables, but I'm running into an issue with the New-ComplianceSearch command. It requires the search query to be in single quotes, which causes my variables to be interpreted as plain text instead of their actual values when the search is created in Purview. Here's the relevant part of my code:

param(
[Parameter(Mandatory)]
$SearchName,
[Parameter(Mandatory)]
$FromAddress,
[Parameter(Mandatory)]
$Subject
)

New-ComplianceSearch -Name "$SearchName" -ExchangeLocation all -ContentMatchQuery 'from:"$FromAddress" AND subject:"$Subject"'

1 Answer

Answered By TechGuru99 On

You might want to try using `$($FromAddress)` and `$($Subject)` in the query. That way, the variables should be correctly evaluated when you run the command!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.