0

我目前正在尝试在 New-ComplianceSearch -ContentMatchQuery ($Variable) 中使用变量,因此我可以使我的内容搜索更加通用而不是静态。

但是,当我查看结果时,查询不会将 $Variable 读取为变量值,而只是将其读取为具有 $Variable 值的字符串。

$complianceSearchName ='1st_Test'
$complianceSearchDesc = 'Test_1'
$keywordField='"Scree*" OR "PC*" OR "Somethin*"'
$senderField='Mailbox Name 1', 'Mailbox Name 2'

New-ComplianceSearch -Name $complianceSearchName -Description $complianceSearchDesc -ExchangeLocation $senderField -ContentMatchQuery  '($keywordField)(c:c)(sent=2020-02-01..2020-02-03)(received=2020-02-01..2020-02-03)'
Start-ComplianceSearch -Identity $complianceSearchName

在 -Name、-Description 和 -ExchangeLocation 中使用 New-ComplianceSearch 时,变量起作用,但是,在 -ContentMatchQuery 中使用 $keywordField 时,会出现错误。

有什么帮助吗?

4

1 回答 1

1

您需要将查询放在双引号中才能使变量扩展工作。

$complianceSearchName ='1st_Test'
$complianceSearchDesc = 'Test_1'
$keywordField='"Scree*" OR "PC*" OR "Somethin*"'
$senderField='Mailbox Name 1', 'Mailbox Name 2'

New-ComplianceSearch -Name $complianceSearchName -Description $complianceSearchDesc -ExchangeLocation $senderField -ContentMatchQuery  "($keywordField)(c:c)(sent=2020-02-01..2020-02-03)(received=2020-02-01..2020-02-03)"
Start-ComplianceSearch -Identity $complianceSearchName

正如你在这里看到的,变量没有用单引号展开。

于 2020-02-24T12:06:53.737 回答