Sam*_*abu 13 powershell powershell-2.0
我试图将数组参数传递给powershell脚本文件.
我试图在命令行中传递这样的命令行.
Powershell -file"InvokeBuildscript.ps1""z:\""Component1","component2"
但它似乎没有采取参数.我错过了什么?如何传递参数数组?
小智 15
简短回答:更多双引号可能会有所帮助......
假设脚本是"test.ps1"
param(
    [Parameter(Mandatory=$False)]
    [string[]] $input_values=@()
)
$PSBoundParameters
假设想传递数组@(123,"abc","x,y,z")
在Powershell控制台下,将多个值作为数组传递
.\test.ps1 -input_values 123,abc,"x,y,z"
在Windows命令提示符控制台或Windows任务计划程序下; 双引号被3个双引号取代
powershell.exe -Command .\test.ps1 -input_values 123,abc,"""x,y,z"""
希望它可以帮助一些人
尝试
Powershell -command "c:\pathtoscript\InvokeBuildscript.ps1" "z:\" "Component1,component2"
如果test.ps1是:
$args[0].GetType()
$args[1].gettype()
从dos shell调用它,如:
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
| 归档时间: | 
 | 
| 查看次数: | 18389 次 | 
| 最近记录: |