{"id":6431,"date":"2008-03-29T00:22:24","date_gmt":"2008-03-29T00:22:24","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/03\/29\/erroraction-silentlycontinue-gt-ea-0\/"},"modified":"2019-02-18T13:16:05","modified_gmt":"2019-02-18T20:16:05","slug":"erroraction-silentlycontinue-gt-ea-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/erroraction-silentlycontinue-gt-ea-0\/","title":{"rendered":"-ErrorAction SilentlyContinue =&#038;gt; -EA 0"},"content":{"rendered":"<p>In PowerShell, we draw the distinction between terminating and non-terminating errors.&#160; The way to think about the distinction is a what should happen if I pipeline a set of objects to an operation.&#160; There are certain errors which mean that there is little to no change that any subsequent object could be processed correctly (for instance if you had a connection that got lost).&#160; These are terminating errors.&#160; <\/p>\n<p>Then there are errors that have no effect on the next operation (for instance, just because you couldn&#8217;t kill one process doesn&#8217;t mean you won&#8217;t be able to kill the next one).&#160; These are non-terminating errors.<\/p>\n<p>Users get to control what happens when a cmdlet issues a non-terminating error.&#160; This is done via the common parameter -ErrorAction.&#160; To examine what values this parameter can take, let&#8217;s use my favorite discovery technique &#8211; input garbage and see what happens:<\/p>\n<p><font face=\"Courier New\" size=\"2\">PS&gt;stop-process 13 -ErrorAction asdf     <br \/><font color=\"#ff0000\">Stop-Process : Cannot bind parameter &#8216;ErrorAction&#8217;. Cannot convert value &quot;asdf&quot; to type &quot;System.Management.Automation.ActionPreference&quot; due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are &quot;<strong>SilentlyContinue, Stop, Continue, Inquire<\/strong>&quot;.        <br \/>At line:1 char:29        <br \/>+ stop-process 13 -ErrorAction &lt;&lt;&lt;&lt;&#160; asdf<\/font><\/font><\/p>\n<p>Great.&#160; So now we know that values we can give it.<\/p>\n<p>&#160;<\/p>\n<p>It just so happens that the thing I do most often is to use the value SilentlyContinue.<\/p>\n<p>This isn&#8217;t so bad in a script but it is quite painful to be a power user and have to type out -ErrorAction SilentlyContinue.&#160; Well because this is PowerShell, you only need to provide enough of the parameter to disambiguate AND we provided an alias &quot;EA&quot; so all you have to type is -EA SilentlyContinue.<\/p>\n<p>So that is better but it is still pretty painful.&#160; So it begs the question &#8211; why &quot;SilentlyContinue&quot; vs &quot;Ignore&quot;.&#160; Sadly, there is no good answer to this one.&#160; I&#8217;ve love to say that someone else on the team made this horrible call but there is a good chance that I screwed that one up (it was a long time ago).&#160; The sad part is that we realized we made a mistake a long time ago but because of the way we develop code and get hardcore about what changes are made when &#8211; it never got to bubble up the queue to get fixed.&#160; 10,000 apologizes for that one.<\/p>\n<p>&#160;<\/p>\n<p>So &#8211; were do we go from here?&#160; <\/p>\n<p>One of the features we have on our dream-list is that when you are specifying an ENUM, PowerShell should be smart enough to let you type just enough to disambiguate and we&#8217;ll figure out the rest.&#160; This would allow you to type:&#160; -ea si&#160; .&#160; Now again, this is not want you want to see in a production script but it would be pretty great for quick interactive use.&#160; <\/p>\n<p>That feature remains a dream and not a plan (at this point).&#160; <\/p>\n<p>Well imagine how delighted I was to see a code example from Keith Hill that solves my problem.&#160;&#160; I forgot that ENUMs are really just INTs.&#160; .NET knows how to cast a string into an ENUM int and we are leveraging that.&#160; BUT is also will cast an INT into an ENUM int.<\/p>\n<p><font face=\"Courier New\" size=\"2\">PS&gt;stop-process 13 -EA 0     <br \/><\/font><font face=\"Courier New\" size=\"2\">PS&gt;stop-process 13 -EA 4     <br \/><font color=\"#ff0000\">Stop-Process : Cannot bind parameter &#8216;ErrorAction&#8217;. Cannot convert value &quot;4&quot; to type &quot;System.Management.Automation.ActionPreference&quot; due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are &quot;SilentlyContinue, Stop, Continue, Inquire&quot;.       <br \/>At line:1 char:20        <br \/>+ stop-process 13 -EA &lt;&lt;&lt;&lt;&#160; 4<\/font><\/font><\/p>\n<p>In other words:&#160; &quot;-EA 0&quot; is exactly the same as &quot;-ErrorAction SilentlyContinue&quot;&#160; except that it is 1\/6th the length!<\/p>\n<p>So when you see a list of ENUMs, it is TYPICALLY (but not always) the case that the values start at 0 and increment.&#160; In all cases, if you know the int value of the enum, you can just use that.<\/p>\n<p>10,000 thanks to Keith Hill for pointing this out.&#160; Boy you just gotta love the PowerShell community!<\/p>\n<p>Jeffrey Snover [MSFT]   <br \/>Windows Management Partner Architect    <br \/>Visit the Windows PowerShell Team blog at:&#160;&#160;&#160; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a>    <br \/>Visit the Windows PowerShell ScriptCenter at:&#160; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In PowerShell, we draw the distinction between terminating and non-terminating errors.&#160; The way to think about the distinction is a what should happen if I pipeline a set of objects to an operation.&#160; There are certain errors which mean that there is little to no change that any subsequent object could be processed correctly (for [&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":[158],"class_list":["post-6431","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-enum"],"acf":[],"blog_post_summary":"<p>In PowerShell, we draw the distinction between terminating and non-terminating errors.&#160; The way to think about the distinction is a what should happen if I pipeline a set of objects to an operation.&#160; There are certain errors which mean that there is little to no change that any subsequent object could be processed correctly (for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6431","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=6431"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6431\/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=6431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=6431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=6431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}