基本上,我试图将退出代码从启动进程返回到脚本,以便在安装失败时 MDT/SCCM 可以正确失败。
通常这里是我正在使用的代码:
$proc = Start-Process -FilePath $setupexe -ArgumentList $setupargs -Wait -Passthrough
Exit $proc.ExitCode
我的问题是什么时候Start-Process
执行?当我定义 $proc 或调用时$proc.ExitCode
?
我要做的是在if
语句中使用退出代码,而不必将该代码存储在另一个变量中(减少代码混乱)。
$proc = Start-Process -FilePath $setupexe -ArgumentList $setupargs -Wait -PassThru
if ($proc.ExitCode -ne 0) {Exit $proc.ExitCode}
$proc2 = Start-Process -FilePath $setupexe2 -ArgumentList $setupargs2 -Wait -PassThru
if ($proc2.ExitCode -ne 0) {Exit $proc.ExitCode}
对比
$proc = Start-Process -FilePath $setupexe -ArgumentList $setupargs -Wait -PassThru
$procexit = $proc.ExitCode
if ($procexit -ne 0) {Exit $procexit}
$proc2 = Start-Process -FilePath $setupexe2 -ArgumentList $setupargs2 -Wait -PassThru
$procexit2 - $proc2.ExitCode
if ($procexit2 -ne 0) {Exit $procexit2}
我不希望Start-Process
仅仅为了杀死脚本并返回错误代码而再次调用。