2012-11-07 33 views

Trả lời

6

thử

Powershell -command "c:\pathtoscript\InvokeBuildscript.ps1" "z:\" "Component1,component2" 

nếu test.ps1 là:

$args[0].GetType() 
$args[1].gettype() 

gọi nó từ một dos shell như:

C:\>powershell -noprofile -command "c:\script\test.ps1" "z:" "a,b" 

lợi nhuận:

IsPublic IsSerial Name          BaseType 
-------- -------- ----          -------- 
True  True  String         System.Object 
True  True  Object[]         System.Array 
8

Câu trả lời ngắn: Nhiều dấu ngoặc kép có thể giúp ...

giả kịch bản là "test.ps1"

param(

    [Parameter(Mandatory=$False)] 
    [string[]] [email protected]() 

) 
$PSBoundParameters 

Giả sử muốn vượt qua mảng @ (123, "abc"," x, y, z ")

Dưới Powershell console, để vượt qua nhiều giá trị như một mảng

.\test.ps1 -input_values 123,abc,"x,y,z" 

Dưới Windows Command Prompt điều khiển hoặc cho Windows Tạ sk Scheduler; Một đôi quote được thay thế bằng 3 dấu nháy kép

powershell.exe -Command .\test.ps1 -input_values 123,abc,"""x,y,z""" 

Hy vọng nó có thể giúp một số

+1

Bí quyết ở đây là sử dụng rõ ràng '-command' thay vì '-file'. –

Các vấn đề liên quan