title: Retrieving MSIEXEC exit code in PowerShell
body: <p>I need to run an <code>MSIEXEC</code> command line from a PowerShell and check whether the installation was successful or not.</p>
  
  <p>If I do:</p>
  
  <pre><code>msiexec.exe /qn /l*v e:/tmp/surfaceruntime.log  /i '\\nas\lui\tools\surfaceruntime2.msi'
  </code></pre>
  
  <p>(where the specified MSI doesn't exist – that's for testing purposes)</p>
  
  <p>I get a <code>$LASTEXITCODE</code> of 1</p>
  
  <p>OTOH, if I do:</p>
  
  <pre><code>$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 
  </code></pre>
  
  <p>I get 1619 (same as <code>%ERRORLEVEL%</code> if I run the command line from <code>CMD</code>).</p>
  
  <p>How come <code>$LASTEXITCODE</code> is incorrect?</p>