在PowerShell中检索MSIEXEC退出代码

14

我需要从PowerShell中运行一个MSIEXEC命令行,并检查安装是否成功。

如果我执行以下操作:

msiexec.exe /qn /l*v e:/tmp/surfaceruntime.log  /i '\\nas\lui\tools\surfaceruntime2.msi'

(指定的 MSI 不存在-这是为了测试目的)

我得到一个$LASTEXITCODE值为1

另一方面,如果我执行以下操作:

$parms=@("/qn", "/l*v", "e:/tmp/surfaceruntime.log";"/i";"\\nas\lui\tools\surfaceruntime2.msi") 

$run=[System.Diagnostics.Process]::Start("msiexec",$parms) 
$run.WaitForExit() 
$run.ExitCode 

如果我从CMD中运行命令行,我将获得1619(与%ERRORLEVEL%相同)。

$LASTEXITCODE为什么不正确?

1个回答

22

试一试:

(Start-Process -FilePath msiexec.exe -ArgumentList $parms -Wait -Passthru).ExitCode

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接