{"id":9491,"date":"2006-10-14T18:10:00","date_gmt":"2006-10-14T18:10:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/10\/14\/windows-powershell-exit-codes\/"},"modified":"2019-02-18T13:21:15","modified_gmt":"2019-02-18T20:21:15","slug":"windows-powershell-exit-codes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/windows-powershell-exit-codes\/","title":{"rendered":"Windows PowerShell Exit Codes"},"content":{"rendered":"<p><!--\n \/* Font Definitions *\/\n @font-face\n\t{font-family:\"Cambria Math\";\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:\"Lucida Console\";\n\tpanose-1:2 11 6 9 4 5 4 2 2 4;}\n@font-face\n\t{font-family:\"Arial Black\";\n\tpanose-1:2 11 10 4 2 1 2 2 2 4;}\n \/* Style Definitions *\/\n p.MsoNormal, li.MsoNormal, div.MsoNormal\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:0in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Lucida Console\";}\nh1\n\t{mso-style-link:\"Heading 1 Char\";\n\tmargin-top:24.0pt;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:0in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tpage-break-after:avoid;\n\tfont-size:14.0pt;\n\tfont-family:\"Lucida Console\";\n\tcolor:#365F91;}\na:link, span.MsoHyperlink\n\t{color:blue;\n\ttext-decoration:underline;}\na:visited, span.MsoHyperlinkFollowed\n\t{color:purple;\n\ttext-decoration:underline;}\np.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Lucida Console\";}\np.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Lucida Console\";}\np.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Lucida Console\";}\np.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Lucida Console\";}\np.Jotest, li.Jotest, div.Jotest\n\t{mso-style-name:\"Jo test\";\n\tmso-style-link:\"Jo test Char\";\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tbackground:#BFBFBF;\n\tfont-size:10.0pt;\n\tfont-family:\"Arial Black\",\"sans-serif\";\n\tfont-weight:bold;}\np.Code, li.Code, div.Code\n\t{mso-style-name:Code;\n\tmso-style-link:\"Code Char\";\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tbackground:#012456;\n\tfont-size:10.0pt;\n\tfont-family:\"Lucida Console\";\n\tcolor:#EEEDF0;}\nspan.JotestChar\n\t{mso-style-name:\"Jo test Char\";\n\tmso-style-link:\"Jo test\";\n\tfont-family:\"Arial Black\",\"sans-serif\";\n\tbackground:#BFBFBF;\n\tfont-weight:bold;}\nspan.Heading1Char\n\t{mso-style-name:\"Heading 1 Char\";\n\tmso-style-link:\"Heading 1\";\n\tfont-family:\"Lucida Console\";\n\tcolor:#365F91;\n\tfont-weight:bold;}\nspan.CodeChar\n\t{mso-style-name:\"Code Char\";\n\tmso-style-link:Code;\n\tcolor:#EEEDF0;\n\tbackground:#012456;}\n.MsoPapDefault\n\t{margin-bottom:10.0pt;\n\tline-height:115%;}\n@page Section1\n\t{size:8.5in 11.0in;\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\ndiv.Section1\n\t{page:Section1;}\n \/* List Definitions *\/\n ol\n\t{margin-bottom:0in;}\nul\n\t{margin-bottom:0in;}\n--><\/p>\n<div class=\"Section1\">\n<h2><span>Windows PowerShell Exit Codes<\/span><\/h2>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>PSMDTAG:FAQ: How can my script control the PowerShell exit code?<\/span><\/p>\n<p class=\"MsoNormal\"><span>Answers:<\/span><\/p>\n<p class=\"MsoListParagraphCxSpFirst\"><span>1.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>A normal termination will set the exitcode to 0<\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span>2.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>An uncaught THROW will set the exitcode to 1<\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\"><span>3.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>The EXIT statement will stop the process and set the exitcode to whatever is specified.<\/span><\/p>\n<p class=\"MsoListParagraphCxSpLast\"><span><\/span>&nbsp;<\/p>\n<p class=\"Code\">c:\\&gt;powershell -noprofile -command &#8220;Write-output Test&#8221;<br \/>Test<\/p>\n<p>c:\\&gt;echo %errorlevel%<br \/>0<\/p>\n<p>c:\\&gt;powershell -noprofile -command &#8220;Write-output Test; throw &#8216;ERROR'&#8221;<br \/>Test<br \/><span>ERROR<br \/>At line:1 char:25<br \/>+ Write-output Test; throw&nbsp; &lt;&lt;&lt;&lt; &#8216;ERROR&#8217;<\/span><\/p>\n<p>c:\\&gt;echo %errorlevel%<br \/>1<\/p>\n<p>c:\\&gt;powershell -noprofile -command &#8220;Write-output Test; exit 31492&#8221;<br \/>Test<\/p>\n<p>c:\\&gt;echo %errorlevel%<br \/>31492<\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp; &nbsp;<a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at<br \/><a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span><\/span>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Windows PowerShell Exit Codes &nbsp; PSMDTAG:FAQ: How can my script control the PowerShell exit code? Answers: 1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A normal termination will set the exitcode to 0 2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; An uncaught THROW will set the exitcode to 1 3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The EXIT statement will stop the process and set the exitcode to whatever is specified. &nbsp; c:\\&gt;powershell -noprofile [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-9491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-faq"],"acf":[],"blog_post_summary":"<p>Windows PowerShell Exit Codes &nbsp; PSMDTAG:FAQ: How can my script control the PowerShell exit code? Answers: 1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A normal termination will set the exitcode to 0 2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; An uncaught THROW will set the exitcode to 1 3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The EXIT statement will stop the process and set the exitcode to whatever is specified. &nbsp; c:\\&gt;powershell -noprofile [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=9491"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9491\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=9491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=9491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=9491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}