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?
Try this:
(Start-Process -FilePath msiexec.exe -ArgumentList $parms -Wait -Passthru).ExitCode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With