{"id":77161,"date":"2016-02-19T11:59:14","date_gmt":"2016-02-19T11:59:14","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=77161"},"modified":"2019-02-18T09:19:49","modified_gmt":"2019-02-18T16:19:49","slug":"powertip-set-erroractionpreference-to-original-value","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-set-erroractionpreference-to-original-value\/","title":{"rendered":"PowerTip: Set ErrorActionPreference to original value"},"content":{"rendered":"<p><strong>Summary<\/strong>: Cloud &amp; Datacenter Management MVP, Thomas Rayner, shows how to work with the <strong>ErrorActionPreference<\/strong> variable in Windows PowerShell.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>\u00a0I have a script that requires me to change the <strong>ErrorActionPreference<\/strong> variable, but how can I set it to its original value after the script is done?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>\u00a0Store the current value of <strong>$ErrorActionPreference<\/strong> and set it again later:<\/p>\n<p style=\"padding-left: 120px\">$OldEAP = $ErrorActionPreference<\/p>\n<p style=\"padding-left: 120px\">$ErrorActionPreference = &#8216;silentlycontinue&#8217;<\/p>\n<p style=\"padding-left: 120px\">#Your script runs in here<\/p>\n<p style=\"padding-left: 120px\">$ErrorActionPreference = $OldEAP<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" alt=\" \" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Cloud &amp; Datacenter Management MVP, Thomas Rayner, shows how to work with the ErrorActionPreference variable in Windows PowerShell. \u00a0I have a script that requires me to change the ErrorActionPreference variable, but how can I set it to its original value after the script is done? \u00a0Store the current value of $ErrorActionPreference and set it [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[639],"tags":[56,356,3,652,45],"class_list":["post-77161","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powertip","tag-guest-blogger","tag-powertip","tag-scripting-guy","tag-thomas-rayner","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Cloud &amp; Datacenter Management MVP, Thomas Rayner, shows how to work with the ErrorActionPreference variable in Windows PowerShell. \u00a0I have a script that requires me to change the ErrorActionPreference variable, but how can I set it to its original value after the script is done? \u00a0Store the current value of $ErrorActionPreference and set it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=77161"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77161\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=77161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=77161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=77161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}