Windows PowerShell Exit Codes
PSMDTAG:FAQ: How can my script control the PowerShell exit code?
Answers:
- A normal termination will set the exitcode to 0
- An uncaught THROW will set the exitcode to 1
- The EXIT statement will stop the process and set the exitcode to whatever is specified.
c:\>powershell -noprofile -command "Write-output Test"
Testc:\>echo %errorlevel%0c:\>powershell -noprofile -command "Write-output Test; throw 'ERROR'"TestERRORAt line:1 char:25+ Write-output Test; throw <<<< 'ERROR'c:\>echo %errorlevel%1c:\>powershell -noprofile -command "Write-output Test; exit 31492"Testc:\>echo %errorlevel%31492
Jeffrey Snover [MSFT]
Windows PowerShell/MMC ArchitectVisit the Windows PowerShell Team blog at: Visit the Windows PowerShell ScriptCenter at