title: Difference between $? and $LastExitCode in PowerShell
body: <p>In PowerShell, what is the difference between <code>$?</code> and <code>$LastExitCode</code>?</p>
  <p>I read <a href="http://technet.microsoft.com/en-us/library/dd347675.aspx" rel="noreferrer">about automatic variables</a>, and it said:</p>
  <blockquote>
  <p><code>$?  Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed.</code></p>
  <p><code>$LastExitCode Contains the exit code of the last Windows-based program that was run.</code></p>
  </blockquote>
  <p>In the definition of <code>$?</code> it doesn't explain what succeed and fail mean.</p>
  <hr />
  <p>I ask because I presumed that <code>$?</code> is True if and only if $LastExitCode is 0, but I found a surprising counter-example: <em><a href="https://stackoverflow.com/questions/10666101">$LastExitCode=0 but $?=False in PowerShell. Redirecting stderr to stdout gives NativeCommandError</a></em>.</p>