Getting MSIEXEC exit code in PowerShell

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

If I do this:

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

(where the specified MSI does not exist - for testing)

I get a $LASTEXITCODE of 1

OTOH, if yes:

 $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 ).

Why is $LASTEXITCODE wrong?

+6
source share
1 answer

Try the following:

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

All Articles