title: How to get a returned value from powershell and get it in a batch file?
body: <p>I'm trying to execute a powershell from a batch file with the commande:
  Powershell .\nameoffile.ps1</p>
  
  <p>The PowerShell returns some values 1, 4, 0 and -1 . How can I get these values from the batch? When I use %errorlevel% it only returns 0 (which means that the script is okay). I have also tried using the Exit command in PowerShell (Exit 4) but It does not work.
  Can you help me?</p>
  
  <p><strong>EDIT</strong> 
  I have found a solution if someone is interested.</p>
  
  <blockquote>
    <p><code>powershell "&amp;{.\test.ps1 %* ;exit $LastExitCode}"  set code=%errorlevel%</code></p>
  </blockquote>