2012-11-08 52 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