我想将参数数组传递给PowerShell脚本文件。如何将参数数组传递给Powershell命令行
我试图在命令行中像这样传递命令行。
Powershell的-file “InvokeBuildscript.ps1” “Z:\” “的Component1”, “COMPONENT2”
但它并不需要它似乎是参数。我错过了什么?如何传递参数数组?
我想将参数数组传递给PowerShell脚本文件。如何将参数数组传递给Powershell命令行
我试图在命令行中像这样传递命令行。
Powershell的-file “InvokeBuildscript.ps1” “Z:\” “的Component1”, “COMPONENT2”
但它并不需要它似乎是参数。我错过了什么?如何传递参数数组?
尝试
Powershell -command "c:\pathtoscript\InvokeBuildscript.ps1" "z:\" "Component1,component2"
如果test.ps1
是:
$args[0].GetType()
$args[1].gettype()
调用它从一个DOS外壳,如:
C:\>powershell -noprofile -command "c:\script\test.ps1" "z:" "a,b"
回报:
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
True True Object[] System.Array
简短的回答:更多双引号可以帮助...
假设脚本是 “test.ps1”
param(
[Parameter(Mandatory=$False)]
[string[]] [email protected]()
)
$PSBoundParameters
假设想传递数组@(123, “ABC”,” X,Y,Z“)
在Powershell的控制台中,对传递多个值作为数组
.\test.ps1 -input_values 123,abc,"x,y,z"
在Windows命令提示控制台或用于Windows的Ta sk调度程序;双引号是由3双引号
powershell.exe -Command .\test.ps1 -input_values 123,abc,"""x,y,z"""
代替希望它可以帮助一些
这里的技巧是使用显式'的-command'代替'-file'。 –