是否可以在 NewComplianceSearch 的 ContentMatchQuery 中使用变量?
Is it possible to use Variables in ContentMatchQuery, in a NewComplianceSearch?
我目前正在尝试在 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 时会发生错误。
有什么帮助吗?
您需要将查询放在双引号中才能进行变量扩展。
$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
如您所见here变量没有用单引号展开。
我目前正在尝试在 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 时会发生错误。
有什么帮助吗?
您需要将查询放在双引号中才能进行变量扩展。
$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
如您所见here变量没有用单引号展开。