0
$cmd = {
    param([System.Array]$filestocopy = $(throw "need files"),
    [bool]$copyxml)
    if($copy)
        #do stuff
}
$files = @("one","two","three")

invoke-command -session $s -scriptblock $cmd -argumentlist (,$files) $copyxml

错误:

Invoke-Command:找不到接受参数“True”的位置参数。

我搜索了高低,找不到如何将数组与参数列表中的内容一起传递。我试过了:(,$files,$copyxml)、、(,$files),$copyxml(,$files) $copyxml

有没有办法做到这一点?

4

1 回答 1

3

参数的参数-ArgumentList必须是一个数组,否则$copyxml将被解释为 的下一个位置参数Invoke-Command。此外,在子表达式 ( ) 中传递数组(,$files)将导致它被破坏。只需传递变量 ( $files) 就足够了。改变这个:

invoke-command -session $s -scriptblock $cmd -argumentlist (,$files) $copyxml

进入这个:

invoke-command -session $s -scriptblock $cmd -argumentlist $files,$copyxml
于 2014-03-20T16:40:13.797 回答