2012-11-08 51 views
6

我需要从PowerShell运行MSIEXEC命令行并检查安装是否成功。检索PowerShell中的MSIEXEC退出代码

如果我做的:

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

(其中指定的MSI不存在 - 这是用于测试目的)

我得到一个1

OTOH的$LASTEXITCODE,如果我这样做:

[email protected]("/qn", "/l*v", "e:/tmp/surfaceruntime.log";"/i";"\\nas\lui\tools\surfaceruntime2.msi") 

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

我得到1619(与%ERRORLEVEL%相同,如果我运行命令li ne从CMD)。

$LASTEXITCODE怎么回事?

回答

7

试试这个:

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