[英]Powershell Remote Invoke-Command Start-Process App Immediately Closes After Launch
[英]Start-Process inside Invoke-Command closes immediately unless -wait switch, but how can I continue script?
我正在尝试远程运行此 Windows Update Assistance Installer.exe,我注意到该 .exe 会立即关闭,除非我使用 -wait 命令。 但是,如果我使用 -wait 命令,我将无法为其他计算机继续我的 foreach 循环,因为完成安装需要数小时。 如果我取出 -wait 命令,我认为它会启动然后立即关闭。
$computers | % {
{more code...}
Invoke-Command -Session $Session -ScriptBlock {
$msbuild = "C:\windows\temp\Windows10Upgrade9252(21H2).exe"
$Args = '/quietinstall /skipeula /auto upgrade /copylogs'
Start-Process -FilePath $msbuild -ArgumentList $args -Wait
}
}
使用 $computers 或 $sessions 作为计算机名/会话名并行运行(在 -throttlelimit 内)。 也可以使用 -asjob。 $args 可能已经被保留。 如果没有进一步的操作,启动进程不会返回文本 output 或退出代码,这是我添加的。 您可以改用计划任务。
$sessions = new-pssession $computers
Invoke-Command $sessions {
$msbuild = "C:\windows\temp\Windows10Upgrade9252(21H2).exe"
$myargs = '/quietinstall /skipeula /auto upgrade /copylogs'
$p = start-process -wait $msbuild $myargs -passthru
[pscustomobject]@{exitcode=$p.exitcode]
} # -asjob
exitcode PSComputerName RunspaceId
-------- -------------- ----------
0 localhost 197d26f5-754b-49d3-baf4-2ca8fccacd4c
等待程序完成的其他方法: 如何告诉 PowerShell 在开始下一个命令之前等待每个命令结束?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.