且构网

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

如何将数组作为参数传递给另一个脚本?

更新时间:2023-11-09 23:34:10

尝试如下:

start-job -filepath myscript.ps1 -arg (,$myarr)

-ArgumentList 接受一个参数列表/数组.因此,当您给出 -arg $myarr 时,就好像您将数组的元素作为参数传递一样.因此,您必须强制 PowerShell 将其视为一个数组参数.

The -ArgumentList takes in a list/array of arguments. So when you give -arg $myarr, it is as though you are passing the elements of the array as the arguments. So you have to force PowerShell to treat it as a single argument which is an array.