且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PowerShell:Start-Job -scriptblock多行脚本块?

更新时间:2023-02-03 21:23:09

briantist 表示敬意,以帮助我到达那里:)

Kudos to briantist for helping me to get there :)

使用Start-JobInvoke-Command时,请注意-ScriptBlock参数的开头{与命令放在同一行.不要像使用ifwhile命令那样将其放在下面的行中.

When using Start-Job and Invoke-Command, be careful to put the opening { for the -ScriptBlock parameter on the same line as the command. Do not put it on the line below as you would with an if or while command.

这会导致进一步的问题,即没有发现您没有正确匹配打开{和关闭}括号,因为您习惯于匹配其缩进级别以将它们配对.

This leads to a the further issue of not spotting that you have not matched opening { and closing } brackets properly, as you are used to the convention of matching their indentation level to pair them up.

请注意,代码中对$Event.timestamp的引用.这些来自以下事实:一个JSON字段称为timestamp-它不是标准字符串或数组的方法或属性.

Please note that the references to $Event.timestamp in the code. These come from the fact that one of the JSON fields is called timestamp - it is not a method or property of a standard string or array.