Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to execute my PowerShell script I get this error:

File C:\Common\Scripts\hello.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:13
+ .\hello.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException

share|improve this question
up vote 169 down vote accepted
  1. Start Windows PowerShell with the "Run as Administrator" option. Only members of the Administrators group on the computer can change the execution policy.

  2. Enable running unsigned scripts by entering:

    set-executionpolicy remotesigned
    

This will allow running unsigned scripts that you write on your local computer and signed scripts from Internet.

See also Running Scripts at Microsoft TechNet Library.

share|improve this answer
17  
+1 for remotesigned instead of unrestricted. You can run your local scripts without exposing yourself to dangers from everywhere else. – DarrellNorton Mar 26 '11 at 13:06
4  
Thanks - this post helped me. However I still had further problems because I hadn't run PowerShell "as Administrator" under win8 – sergeantKK Nov 29 '12 at 13:46

The Default Execution Policy is set to restricted, you can see it by typing:

Get-ExecutionPolicy

You should type the following to make it go to unrestricted mode:

Set-ExecutionPolicy unrestricted

Hope this helps

share|improve this answer
12  
-1. that is WAY too open to just execute. RemoteSigned is better. – TomTom Jul 17 '12 at 20:38
13  
The requiring signing make sense if you expect the user to copy&paste malicious scripts from the internet. If you assume the user isn't stupid, then "remotesigned" doesn't add any security and makes life difficult. – Guss Nov 11 '12 at 10:41

On my machine that I use to dev scripts, I will use -unrestricted as above. When deploying my scripts however, to an end user machine, I will just call powershell with the -executionpolicy switch:

powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
share|improve this answer
2  
You may want to combine this trick with a polyglot trick in a .CMD file. See stackoverflow.com/a/8597794/5314 – Jay Bazuzi Jan 14 '13 at 20:30
    
Nice! I've been deploying sfx's made by winrar rarlabs.com – BigHomie Jan 15 '13 at 16:09
1  
That trick allowed me to run powershell script from Git Bash (MINGW32 bash) – Kamil Szot Apr 19 '14 at 21:10

Depending on the Windows version and configuration, you may have the following warning, even in Unrestricted mode:

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this
script can potentially harm your computer. If you trust this script, use the 
Unblock-File cmdlet to allow the script to run without this warning message. 
Do you want to run?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D")

The solution is to use the "bypass" policy, enabled with the following command:

Set-ExecutionPolicy Bypass

From the documentation:

Bypass: Nothing is blocked and there are no warnings or prompts.

This is obviously insecure, please understand the risks involved.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.