且构网

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

将参数传递给 powershell 中的脚本块

更新时间:2023-01-08 18:45:22

Keith 的回答 也适用于 Invoke-Command,有不能使用命名参数的限制.参数应使用 -ArgumentList 参数设置,并应以逗号分隔.

Keith's answer also works for Invoke-Command, with the limit that you can't use named parameters. The arguments should be set using the -ArgumentList parameter and should be comma separated.

$sb = {
    param($p1,$p2)
    $OFS=','
    "p1 is $p1, p2 is $p2, rest of args: $args"
}
Invoke-Command $sb -ArgumentList 1,2,3,4

另请参阅此处此处.