2017-04-25 107 views
0

我已調查此論壇。但似乎沒有足夠的理解我的答案。我絕對是Powershell的新手。將參數從PowerShell腳本傳遞到另一個

我有一種情況,我已經開始ps1腳本,需要執行另一個ps1腳本在後臺啓動,從第一個腳本傳遞參數到第二個腳本。

像這樣的東西(script1.ps1):

$var1 = "p1 (string value)" 
$var2 = "p2 (string value)" 
$var3 = "p3 (string value)" 
$var4 = 4 # numeric value 

$counter = 1 

while ($counter -le $var4) 
{ 
    #call to script2.ps1 with passing the $var1 through $var4 as 
    #parameters so that script2.ps1 executes as a background process 
    #and works with the received parameters $var1 through $var4 
    # ?? 
    $counter= $counter + 1 
} 

exit 
######################################## 

我找不到傳遞的參數,並在後臺啓動script2.ps1 1路。

真的希望有人能幫助我。

THIA, 維姆

+0

爲什麼你不想將它們作爲數組傳遞並在腳本中逐個處理它們? – 4c74356b41

回答

0

這奏效了我。

$var1 = "p1 (string value)" 
$var2 = "p2 (string value)" 
$var3 = "p3 (string value)" 
$var4 = 4 # numeric value 

$counter = 1 
while ($counter -le $var4) 
{ 

    $Params = "-Param1 $var1 -Param2 $var2 -Param3 $var3" 
    $Script = [scriptblock]::create("d:\temp\scriptname.ps1 $Params") 
    Start-Job -ScriptBlock $Script 

    $counter = $counter+1 
} 

exit 
相關問題