{"id":9631,"date":"2006-09-15T00:04:00","date_gmt":"2006-09-15T00:04:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/09\/15\/errorlevel-equivalent\/"},"modified":"2019-02-18T13:21:20","modified_gmt":"2019-02-18T20:21:20","slug":"errorlevel-equivalent","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/errorlevel-equivalent\/","title":{"rendered":"ErrorLevel equivalent"},"content":{"rendered":"<p>PSMDTAG:FAQ: ErrorLevel &#8211; what is the PowerShell equivalent?<\/p>\n<p>In Cmd.exe, %ErrorLevel% is a builtin variable which indicates the success or failure of the last&nbsp;executable run.<\/p>\n<p>In PowerShell, we support:<\/p>\n<p>&nbsp;&nbsp;&nbsp; $?<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contains True if last operation succeeded and False otherwise.<br \/>And<\/p>\n<p>&nbsp;&nbsp;&nbsp; $LASTEXITCODE<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contains the exit code of the last Win32 executable execution.<\/p>\n<p><font face=\"Courier New\" size=\"1\">PS&gt; <strong><font color=\"#000080\">2+2<br \/><\/font><\/strong>4<br \/>PS&gt;<strong><font color=\"#000080\"> $?<br \/><\/font><\/strong>True<br \/>PS&gt;<strong><font color=\"#000080\"> 3\/$null<br \/><\/font><\/strong>Attempted to divide by zero.<br \/>At line:1 char:3<br \/>+ 3\/$ &lt;&lt;&lt;&lt; null<br \/>PS&gt; <font color=\"#000080\"><strong>$?<br \/><\/strong><\/font>False<br \/>PS&gt;<br \/>PS&gt;<strong><font color=\"#000080\"> ping localhost<\/font><\/strong><\/font><\/p>\n<p><font face=\"Courier New\" size=\"1\">Pinging jpsvista1.ntdev.corp.microsoft.com [::1] from ::1 with 32 bytes of data:<\/font><\/p>\n<p><font face=\"Courier New\" size=\"1\">Reply from ::1: time&lt;1ms<br \/>Reply from ::1: time&lt;1ms<br \/>Reply from ::1: time&lt;1ms<br \/>Reply from ::1: time&lt;1ms<\/font><\/p>\n<p><font face=\"Courier New\" size=\"1\">Ping statistics for ::1:<br \/>&nbsp;&nbsp;&nbsp; Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br \/>Approximate round trip times in milli-seconds:<br \/>&nbsp;&nbsp;&nbsp; Minimum = 0ms, Maximum = 0ms, Average = 0ms<br \/>PS&gt; <font color=\"#000080\"><strong>$lastexitcode<br \/><\/strong><\/font>0<br \/><\/font><font face=\"Courier New\" size=\"1\">PS&gt; <strong><font color=\"#000080\">ping asdfasdf<\/font><\/strong><br \/>Ping request could not find host asdfasdf. Please check the name and try again.<br \/>PS&gt; <font color=\"#000080\"><strong>$lastexitcode<\/strong><\/font><br \/>1<\/font><\/p>\n<p>&nbsp;<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/Aspen 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:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>PSMDTAG:ERROR: %ErrorLevel% , $? and $LastExitCode<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PSMDTAG:FAQ: ErrorLevel &#8211; what is the PowerShell equivalent? In Cmd.exe, %ErrorLevel% is a builtin variable which indicates the success or failure of the last&nbsp;executable run. In PowerShell, we support: &nbsp;&nbsp;&nbsp; $?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contains True if last operation succeeded and False otherwise.And &nbsp;&nbsp;&nbsp; $LASTEXITCODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contains the exit code of the last Win32 executable execution. PS&gt; 2+24PS&gt; $?TruePS&gt; [&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":[62,63,10],"class_list":["post-9631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-lastexitcode","tag-errorlevel","tag-faq"],"acf":[],"blog_post_summary":"<p>PSMDTAG:FAQ: ErrorLevel &#8211; what is the PowerShell equivalent? In Cmd.exe, %ErrorLevel% is a builtin variable which indicates the success or failure of the last&nbsp;executable run. In PowerShell, we support: &nbsp;&nbsp;&nbsp; $?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contains True if last operation succeeded and False otherwise.And &nbsp;&nbsp;&nbsp; $LASTEXITCODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contains the exit code of the last Win32 executable execution. PS&gt; 2+24PS&gt; $?TruePS&gt; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9631","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=9631"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9631\/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=9631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=9631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=9631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}