数组传递到另一个脚本调用命令 [英] Passing array to another script with Invoke-Command
问题描述
我卡试图弄清楚这一点。我见过的其他文章,并尝试了一切,但我没有得到任何地方。我想传递一个数组作为参数传递给另外一个PS脚本。下面是我尝试:
I'm stuck trying to figure this out. I've seen the other articles and have tried everything, but I'm not getting anywhere. I am trying to pass an array as an argument to another PS script. Here's what I'm trying:
$IPArray = Get-Content C:\ListofIps.txt
Invoke-Command -Computername $server -Credential $cred -FilePath "C:\script.ps1" -ArgumentList (,$IPArray)
在$ IPArray 5值不会被传递到我调用脚本。
The 5 values in $IPArray aren't being passed to the script that I call.
在此先感谢,伙计们,我真的AP preciate任何帮助,您可以给...
Thanks in advance, guys, I really appreciate any help you can give...
推荐答案
使用:
... -ArgumentList (,$IPArray)
由于该参数列表
参数期望你正确地指出,你需要用数组中的另一个数组的数组。然而,在这种情况下(指定参数值)的正确语法是使用分组前pression ()
以创建嵌套数组。
Because the ArgumentList
parameter expects an array you've correctly noted that you need to wrap the array in another array. However, the correct syntax in this scenario (specifying a parameter value) is to use a grouping expression ()
to create the nested array.
这篇关于数组传递到另一个脚本调用命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!