在PowerShell中检索MSIEXEC退出代码

sba*_*sba 10 powershell msiexec

我需要MSIEXEC从PowerShell 运行命令行并检查安装是否成功.

如果我做:

msiexec.exe /qn /l*v e:/tmp/surfaceruntime.log  /i '\\nas\lui\tools\surfaceruntime2.msi'
Run Code Online (Sandbox Code Playgroud)

(指定的MSI不存在 - 用于测试目的)

我得到$LASTEXITCODE1分

OTOH,如果我这样做:

$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 
Run Code Online (Sandbox Code Playgroud)

我得到1619(就像%ERRORLEVEL%我从命令行运行一样CMD).

怎么回事$LASTEXITCODE不对?

Dav*_*tin 11

试试这个:

(Start-Process -FilePath msiexec.exe -ArgumentList $parms -Wait -Passthru).ExitCode
Run Code Online (Sandbox Code Playgroud)