Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 296
sba923 Avatar asked Nov 08 '12 10:11

sba923


1 Answers

Try this:

(Start-Process -FilePath msiexec.exe -ArgumentList $parms -Wait -Passthru).ExitCode
like image 181
David Martin Avatar answered Sep 19 '22 12:09

David Martin