Click here to Skip to main content
14,972,394 members
Articles / Desktop Programming / System
Tip/Trick
Posted 3 Dec 2020

Stats

2.1K views
1 bookmarked

Error "Execution of scripts is disabled on this system" when run PowerShell script on Windows PowerShell Command Prompt

Rate me:
Please Sign up or sign in to vote.
2.25/5 (3 votes)
3 Dec 2020CPOL1 min read
About "Execution of scripts is disabled on this system" error that people get when they run any PowerShell command for the first time
"Execution of scripts is disabled on this system" is a very common error. The error itself says that execution of any script on this system is disabled and usually, you get this error when you run any PowerShell script for the first time on any computer.

Easy Fixes

Mostly everyone is interested in easier and quicker way to fix it, so before going in depth, I will directly tell you the solution. After fixing the issue, if you are interested to know more details, please go through this tip.

To fix this issue, open Windows PowerShell as an administrator and after opening a window, execute the below command:

Set-ExecutionPolicy Unrestricted

Note: If you run the above command without administrative rights, you will get an error as below, which will tell you to open Windows PowerShell with the "Run as administrator" option.

Set-ExecutionPolicy : Access to the registry key
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
To change the execution policy for the default (LocalMachine) scope, 
start Windows PowerShell with the "Run as administrator" option. To
change the execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".

What This Error Means?

Let's see now what this error means. This is very common error and the error itself says that execution of any script on this system is disabled and usually, you get this error when you run any PowerShell script for the first time on any computer.

There are four different types of execution policies in PowerShell:

  • Restricted: If this policy is set, then any script can't be executed.
  • RemoteSigned: If this policy is set, then only downloaded script from the Internet can be executed and those scripts must be signed by the trusted publisher.
  • Unrestricted: If this policy is set, then any type of script can be executed.
  • AllSigned: If this policy is set, then only signed by a trusted publisher script can be executed.

Default policy of Windows PowerShell is "restricted", so to run the above script, we need to change it to "Unrestricted" by using command `Set-ExecutionPolicy Unrestricted`.

If you want to set unrestricted for particular user or current user, then as specified in the error, you can run the below command:

Set-ExecutionPolicy -Scope CurrentUser

History

  • 3rd December, 2020: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Gaurang Majithiya
Technical Lead
India India
I am working as a Project Manager (Technical) in Ahmedabad, Gujarat, India.

I have total 15+ years of experience in Microsoft Technologies like ASP.NET, C#.NET, .NET Core, JavaScript, JQuery, React JS etc.

Comments and Discussions

 
QuestionRemoteSigned means local scripts need not be signed Pin
David Maw8-Dec-20 8:55
MemberDavid Maw8-Dec-20 8:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.