我调查了这个论坛。但似乎并不理解它足以找到我的答案。我是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
########################################
我找不到1种传递参数的方法,并在后台启动script2.ps1。
真的希望有人可以帮助我。
THIA, 维姆
答案 0 :(得分:1)
这将有助于您About_Jobs
Get-Help Start-Job
https://sqlblog.org/2011/01/29/powershell-start-job-scriptblock-sad-panda-face
答案 1 :(得分: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