How To Enable "running Scripts" On Your System

Have you ever been in a situation where you cannot perform specific tasks on your source code editor? For instance, in trying to activate a virtual environment on your editor, you come across an error that says, "the command cannot be loaded on your system because running scripts is disabled on your system". We'll take a look at how to solve this in this article.

NOTE: Trying to activate a virtual environment on your editor is one of the commands that could lead to this error, as several commands could lead to this specified error.

What Causes This Error?

First, you should know that your source code editor is synced with Powershell and that the error occurs due to the Powershell Execution Policy. You can check out the link in your editor's terminal to know more about this Policy.

The Powershell execution Policy is a security feature that regulates the circumstances under which the program reads configuration files and executes scripts. This function aids in preventing dangerous scripts from running. We can see that the Policy was set up for security reasons.

Now, you're encountering an error on your editor because the Policy has been set to either Undefined or Restricted on your system.

According to the Microsoft Powershell, when set to Restricted, this is what the Policy does;

  • The default execution policy for Windows client computers.
  • Permits individual commands but does not allow scripts.
  • Prevents running of all script files, including formatting and configuration files (.ps1xml), module script files (.psm1), and PowerShell profiles (.ps1).

When it is set to Undefined, this is what it does:

  • There is no execution policy set in the current scope.
  • If the execution policy in all scopes is Undefined, the effective execution policy is Restricted for Windows clients and RemoteSigned for Windows Server.

NOTE: It is essential to know about these policies before altering any changes thus check out the link: Microsoft Powershell

How Do You Fix This Error?

You can fix this error by trying out the following steps:

  • Search for Powershell on your system and click on the "run as administrator" icon.

powershell.JPG

  • Type Get-ExecutionPolicy -List to see the execution policy status
  • Type Set-ExecutionPolicy Unrestricted Capture.JPG

  • Next, you'll be asked a question and given an option to proceed with the process or suspend the process ( You'll see an option to either type [Y] to proceed [N] to suspend and in most cases [A] as an option to say yes to all processes). It would help if you then chose either the [Y] or the [A] (this is because some systems don't usually have the [A] option, but in any case, both options would perform the task.

If you've done the above steps, you should head into your editor and rerun the command, and you will notice that the error isn't occurring any longer. It is because you've changed the Execution Policy.

Please share if you found this helpful.