<p>I wrote a simple batch file as a PowerShell script, and I am getting errors when they run.</p>

<p>It's in a scripts directory in my path. This is the error I get:</p>

<blockquote>
  <p>Cannot be loaded because the execution of scripts is disabled on this system. 
   Please see "get-help about-signing".</p>
</blockquote>

<p>I looked in the help, but it's less than helpful.</p>

[{'answer_id': 10638, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 8, 'selected': True, 'text': '<p>It could be PowerShell\'s default security level, which (IIRC) will only run signed scripts.</p>\n\n<p>Try typing this:</p>\n\n<pre class="lang-none prettyprint-override"><code>set-executionpolicy remotesigned\n</code></pre>\n\n<p>That will tell PowerShell to allow local (that is, on a local drive) unsigned scripts to run.</p>\n\n<p>Then try executing your script again.</p>\n'}, {'answer_id': 10640, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 3, 'selected': False, 'text': "<p>Also it's worth knowing that you may need to include <code>.\\</code> in front of the script name. For example: </p>\n\n<pre><code>.\\scriptname.ps1\n</code></pre>\n"}, {'answer_id': 11549657, 'author': 'ExchangeAdmin', 'author_id': 1536046, 'author_profile': 'https://Stackoverflow.com/users/1536046', 'pm_score': 1, 'selected': False, 'text': '<p>The command <code>set-executionpolicy unrestricted</code> will allow any script you create to run as the logged in user. Just be sure to set the executionpolicy setting back to signed using the <code>set-executionpolicy signed</code> command prior to logging out. </p>\n'}, {'answer_id': 16141428, 'author': 'Naveen', 'author_id': 2306339, 'author_profile': 'https://Stackoverflow.com/users/2306339', 'pm_score': 5, 'selected': False, 'text': '<p>Use:</p>\n\n<pre><code>Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process\n</code></pre>\n\n<p>Always use the above command to enable to executing PowerShell in the current session.</p>\n'}, {'answer_id': 19974975, 'author': 'Nadeem_MK', 'author_id': 2416510, 'author_profile': 'https://Stackoverflow.com/users/2416510', 'pm_score': 6, 'selected': False, 'text': '<p>You need to run <code>Set-ExecutionPolicy</code>:</p>\n\n<pre class="lang-none prettyprint-override"><code>Set-ExecutionPolicy Restricted &lt;-- Will not allow any powershell scripts to run.  Only individual commands may be run.\n\nSet-ExecutionPolicy AllSigned &lt;-- Will allow signed powershell scripts to run.\n\nSet-ExecutionPolicy RemoteSigned &lt;-- Allows unsigned local script and signed remote powershell scripts to run.\n\nSet-ExecutionPolicy Unrestricted &lt;-- Will allow unsigned powershell scripts to run.  Warns before running downloaded scripts.\n\nSet-ExecutionPolicy Bypass &lt;-- Nothing is blocked and there are no warnings or prompts.\n</code></pre>\n'}, {'answer_id': 21922658, 'author': 'user3335140', 'author_id': 3335140, 'author_profile': 'https://Stackoverflow.com/users/3335140', 'pm_score': 3, 'selected': False, 'text': "<pre><code>Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process\n</code></pre>\n\n<p>The above command worked for me even when the following error happens:</p>\n\n<pre><code>Access to the registry key 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\PowerShell\\1\\ShellIds\\Microsoft.PowerShell' is denied.\n</code></pre>\n"}, {'answer_id': 34007144, 'author': 'Be Kind To New Users', 'author_id': 192044, 'author_profile': 'https://Stackoverflow.com/users/192044', 'pm_score': 4, 'selected': False, 'text': '<p>I was able to bypass this error by invoking PowerShell like this:</p>\n\n<pre><code>powershell -executionpolicy bypass -File .\\MYSCRIPT.ps1\n</code></pre>\n\n<p>That is, I added the <code>-executionpolicy bypass</code> to the way I invoked the script.</p>\n\n<p>This worked on Windows 7 Service Pack 1. I am new to PowerShell, so there could be caveats to doing that that I am not aware of.</p>\n\n<p>[Edit 2017-06-26] I have continued to use this technique on other systems including Windows 10 and Windows 2012 R2 without issue.</p>\n\n<p>Here is what I am using now. This keeps me from accidentally running the script by clicking on it. When I run it in the scheduler I add one argument: "scheduler" and that bypasses the prompt.</p>\n\n<p>This also pauses the window at the end so I can see the output of PowerShell.</p>\n\n<pre><code>if NOT "%1" == "scheduler" (\n   @echo looks like you started the script by clicking on it.\n   @echo press space to continue or control C to exit.\n   pause\n)\n\nC:\ncd \\Scripts\n\npowershell -executionpolicy bypass -File .\\rundps.ps1\n\nset psexitcode=%errorlevel%\n\nif NOT "%1" == "scheduler" (\n   @echo Powershell finished.  Press space to exit.\n   pause\n)\n\nexit /b %psexitcode%\n</code></pre>\n'}, {'answer_id': 58025263, 'author': 'user2781940', 'author_id': 2781940, 'author_profile': 'https://Stackoverflow.com/users/2781940', 'pm_score': 0, 'selected': False, 'text': '<p>On Windows 10: \nClick change security property of myfile.ps1 and change "allow access" by right click / properties on myfile.ps1</p>\n'}, {'answer_id': 64084268, 'author': 'Wasif', 'author_id': 12269857, 'author_profile': 'https://Stackoverflow.com/users/12269857', 'pm_score': 1, 'selected': False, 'text': '<p>We can bypass execution policy in a nice way (inside command prompt):</p>\n<pre><code>type file.ps1 | powershell -command -\n</code></pre>\n<p>Or inside powershell:</p>\n<pre><code>gc file.ps1|powershell -c -\n</code></pre>\n'}, {'answer_id': 67022880, 'author': 'Christian Brüggemann', 'author_id': 1502352, 'author_profile': 'https://Stackoverflow.com/users/1502352', 'pm_score': 0, 'selected': False, 'text': "<p>It would be ideal to bypass execution policies e.g. through</p>\n<pre><code>powershell -executionpolicy bypass -File .\\MYSCRIPT.ps1\n</code></pre>\n<p>Unfortunately this can still be prevented by group policies. As a workaround, you can encode your script as Base64 by running this in PowerShell:</p>\n<pre><code>[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes((Get-Content .\\MYSCRIPT.ps1)))\n</code></pre>\n<p>Then execute the result like this:</p>\n<pre><code>powershell.exe -EncodedCommand &quot;put-your-base64-string-here&quot;\n</code></pre>\n<p>Caveat: This won't work with scripts that require parameters.</p>\n"}]
['https://Stackoverflow.com/questions/10635', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1220/']