Reputation: 15044
$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
Error:
Invoke-Command : A positional parameter cannot be found that accepts argument 'True'.
I have searched high and low and cannot find how to pass in an array along with something in a argumentlist. I have tried: (,$files,$copyxml)
, (,$files),$copyxml
, and (,$files) $copyxml
Is there a way to do this?
Upvotes: 0
Views: 208
Reputation: 200493
The argument to the parameter -ArgumentList
must be an array, otherwise $copyxml
will be interpreted as the next positional parameter to Invoke-Command
. Also, passing the array in a subexpression ((,$files)
) will cause it to be mangled. Simply passing the variable ($files
) is sufficient. Change this:
invoke-command -session $s -scriptblock $cmd -argumentlist (,$files) $copyxml
into this:
invoke-command -session $s -scriptblock $cmd -argumentlist $files,$copyxml
Upvotes: 3