sba923
sba923

Reputation: 575

Retrieving MSIEXEC exit code in PowerShell

I need to run an MSIEXEC command line from a PowerShell and check whether the installation was successful or not.

If I do:

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

(where the specified MSI doesn't exist – that's for testing purposes)

I get a $LASTEXITCODE of 1

OTOH, if I do:

$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 

I get 1619 (same as %ERRORLEVEL% if I run the command line from CMD).

How come $LASTEXITCODE is incorrect?

Upvotes: 14

Views: 16153

Answers (1)

David Martin
David Martin

Reputation: 12248

Try this:

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

Upvotes: 22

Related Questions