Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / system

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

2.25/5 (3 votes)
3 Dec 2020CPOL1 min read 6.3K  
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)