【发布时间】:2017-11-19 12:52:35
【问题描述】:
使用 Start-Job 和 ArgumentList,如何将一个数组和另一个变量传递给接收脚本?
如果我只需要传递一个数组,这很有效
Start-Job -FilePath "c:\thescript.ps1" -ArgumentList (,$newArray)
试过了,但接收脚本中没有使用第二个值。
Start-Job -FilePath "c:\thescript.ps1" -ArgumentList (,$newArray,"x")
thescript.ps1 示例:
param (
[string[]]$aMyArray,
[string]$sMyString
)
function DoWork ([string]$aItem,[string]$sMyString)
{
#worker
}
foreach($aItem in $aMyArray)
{
DoWork $aItem $sMyString
}
我目前正在使用 PowerShell 2.0
【问题讨论】:
-
从括号中取出 x。您不使用逗号来分隔参数。否则,它们会被视为单个对象。
-
@Matt 这就是你的建议? -ArgumentList (,$newArray) "x"
-
是的。这完全取决于您的用例以及 script.ps1 的配置方式。
-
@Briantist。他知道如何传递数组。这是他遇到问题的下一个论点。我一直在寻找一个多参数的骗子,但没有找到我喜欢的。
-
@Matt 我知道你是对的;重新打开。
标签: arrays powershell parameter-passing powershell-2.0