2012-11-07 18 views

risposta

6

provare

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

se test.ps1 è:

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

chiamata da un dos shell come:

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

rendimenti:

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

Risposta breve: le citazioni più doppi potrebbe aiutare ...

suppongono la sceneggiatura è "test.ps1"

param(

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

) 
$PSBoundParameters 

Supponiamo che vorrebbe passare la matrice @ (123, "abc"," x, y, z ")

Sotto console Powershell, per passare più valori come array

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

Sotto console comandi Windows o per Windows Ta sk Scheduler; Un doppio-citazione sono sostituiti da 3 virgolette

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

Spero potrebbe aiutare alcuni

+1

Il trucco è quello di utilizzare esplicito '-command' invece di' -file'. –

Problemi correlati