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