使用 Invoke-Command 将数组传递给另一个脚本 [英] Passing array to another script with Invoke-Command

查看:28
本文介绍了使用 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.

提前致谢,伙计们,我真的很感谢你能提供的任何帮助......

Thanks in advance, guys, I really appreciate any help you can give...

推荐答案

使用:

... -ArgumentList (,$IPArray)

因为 ArgumentList 参数需要一个数组,您已经正确地注意到您需要将该数组包装在另一个数组中.但是,此场景中的正确语法(指定参数值)是使用分组表达式 () 来创建嵌套数组.

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.

这篇关于使用 Invoke-Command 将数组传递给另一个脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆