{"id":62,"date":"2024-02-25T17:13:15","date_gmt":"2024-02-25T16:13:15","guid":{"rendered":"https:\/\/duelund.tech\/?p=62"},"modified":"2025-04-10T13:00:00","modified_gmt":"2025-04-10T11:00:00","slug":"silently-bypass-execution-policy-when-running-a-powershell-script","status":"publish","type":"post","link":"https:\/\/duelund.tech\/index.php\/2024\/02\/25\/silently-bypass-execution-policy-when-running-a-powershell-script\/","title":{"rendered":"Silently bypass execution policy when running a PowerShell script"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When running a PowerShell script, you might sometimes encounter systems where the execution policy prevents the script from running.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A quick workaround is to use a batch script to call the PowerShell script. This also allows you to create a desktop shortcut, which is useful if it&#8217;s a script you run frequently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PowerShell lets you bypass the execution policy, so what the batch script essentially does is start PowerShell with the <strong>-ExecutionPolicy Bypass<\/strong> parameter and run the script \u2014 plain and simple.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"984\" height=\"517\" src=\"https:\/\/duelund.tech\/wp-content\/uploads\/2024\/02\/2024-02-25_17h07_07.png\" alt=\"\" class=\"wp-image-66\" srcset=\"https:\/\/duelund.tech\/wp-content\/uploads\/2024\/02\/2024-02-25_17h07_07.png 984w, https:\/\/duelund.tech\/wp-content\/uploads\/2024\/02\/2024-02-25_17h07_07-300x158.png 300w, https:\/\/duelund.tech\/wp-content\/uploads\/2024\/02\/2024-02-25_17h07_07-768x404.png 768w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To get started, either download the script or copy the one below, paste it into your favorite text editor, and save it as a batch file <strong>(<code>.bat<\/code>)<\/strong>. All you need to do is update the quoted path to point to your PowerShell script.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-dc819ceb-2871-4aa0-bb9c-0d959b39f0a5\" href=\"https:\/\/duelund.tech\/wp-content\/uploads\/2024\/02\/BypassExecutionPolicy-Duelund_tech.zip\">BypassExecutionPolicy-Duelund_tech.zip<\/a><a href=\"https:\/\/duelund.tech\/wp-content\/uploads\/2024\/02\/BypassExecutionPolicy-Duelund_tech.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-dc819ceb-2871-4aa0-bb9c-0d959b39f0a5\">Download<\/a><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"@echo off\n\nPowerShell -NoProfile -ExecutionPolicy Bypass -File &quot;C:\\Scripts\\PowerShell\\YourScriptFile.ps1&quot;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">@echo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">off<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">PowerShell<\/span><span style=\"color: #D8DEE9FF\"> -NoProfile -ExecutionPolicy Bypass -File <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">C:\\Scripts\\PowerShell\\YourScriptFile.ps1<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>When running a PowerShell script, you might sometimes encounter systems where the execution policy prevents the script from running. A quick workaround is to use a batch script to call the PowerShell script. This also allows you to create a desktop shortcut, which is useful if it&#8217;s a script you run frequently. PowerShell lets you&hellip;&nbsp;<a href=\"https:\/\/duelund.tech\/index.php\/2024\/02\/25\/silently-bypass-execution-policy-when-running-a-powershell-script\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Silently bypass execution policy when running a PowerShell script<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[12,11,2,17],"tags":[24,22,20,19,21,23],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-batch","category-powershell","category-scripts","category-windows","tag-bat","tag-batch","tag-bypass","tag-executionpolicy","tag-powershell","tag-ps1"],"_links":{"self":[{"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":6,"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/posts\/62\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/duelund.tech\/index.php\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}