交换 Shell - SubjectOrBodyContainsWords

Exchange Shell - SubjectOrBodyContainsWords

我正在尝试为每个脚本创建规则,但我无法继续,因为我似乎达到了太高的值...

[PS] C:\Users\XXX\Desktop>New-InboxRule -Mailbox "Daniel.XXX" -Name "Test" -SubjectOrBodyContainsWords {"Value1","Value2","Value3","Value4","Value5","Value6","Value7","Value8","Value9","Value10","Value11","Value12","Value13","Value14","Value15","Value16","Value17","Value18","alue19","Value20","Value21","Value22","Value23","Value24","Value25","alue26","Value27","Value28","Value29","Value30","Value31","Value32","alue33","Value34","Value35","Value36","Value37","alue38","Value39","Value40","Value41","Value42","Value43","Value44","Value45","Value46","Value47","Value48","Value49","alue50","Value51","Value52","Value53","Value54","Value55","Value56","Value57","Value58"} -ApplyCategory "Common CA" -WHATIF

Invoke-Command : Cannot bind parameter 'SubjectOrBodyContainsWords' to the target. Exception setting "SubjectOrBodyContainsWords": "The length of the property is too long. The maximum length is 255 and the length of the value provided is 570."AtC:\Users\XXX\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\XXXXXXXXXXXXX.psm1:20346 char:29 + $scriptCmd = { & <<<< $script:InvokeCommand ` + CategoryInfo : WriteError: (:) [New-InboxRule], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.NewInboxRule

如果我用可接受的值设置规则并在 Exchange 控制面板中查看它,我只会看到文本作为一个值(一个大字符串)而不是多个值(如果我要通过 GUI 创建它)...

我做错了什么?

根据about_Parsing帮助文件:

When processing a command, the Windows PowerShell parser operates in expression mode or in argument mode:

- In argument mode, each value is treated as an expandable string 
  unless it begins with one of the following special characters: dollar
  sign ($), at sign (@), single quotation mark ('), double quotation
  mark ("), or an opening parenthesis (().

由于您对 SubjectOrBodyContainsWords 参数的论证以 { 开头,解析器将整个列表视为 一个大字符串 。只需删除大括号(或替换为常规括号):

New-InboxRule -Mailbox 'Daniel.XXX' -Name 'Test' -SubjectOrBodyContainsWords ("Value1","Value2","Value3","Value4","Value5","Value6","Value7","Value8","Value9","Value10","Value11","Value12","Value13","Value14","Value15","Value16","Value17","Value18","alue19","Value20","Value21","Value22","Value23","Value24","Value25","alue26","Value27","Value28","Value29","Value30","Value31","Value32","alue33","Value34","Value35","Value36","Value37","alue38","Value39","Value40","Value41","Value42","Value43","Value44","Value45","Value46","Value47","Value48","Value49","alue50","Value51","Value52","Value53","Value54","Value55","Value56","Value57","Value58")

为了使命令更具可读性,我可能会事先将可能的值分配给数组:

$SOBCWords = @(
"Value1",
"Value2",
"Value3",
# etc
"Value56",
"Value57",
"Value58"
)
New-InboxRule -Mailbox "Daniel.XXX" -Name "Test" -SubjectOrBodyContainsWords $SOBCWords -ApplyCategory "Common CA" -WHATIF