How to Fix "Running scripts is disabled on this system" PowerShell Error

This article explains the "Running scripts is disabled on this system" Powershell error which is designed to protect your system. You also learn how to resolve the error.

"Running scripts is disabled on this system" PowerShell Error
"Running scripts is disabled on this system" PowerShell Error

PowerShell is a powerful and versatile scripting language and command-line shell developed by Microsoft. It's an essential tool for system administrators, developers, and power users, as it allows for automation, management, and execution of tasks on Windows-based systems.

While automating or managing tasks, you might encounter an error that says, Running scripts is disabled on this system. This error typically occurs when you attempt to run PowerShell scripts or execute certain commands.

Fortunately, it's a security feature designed to protect your system, and it can be resolved by adjusting your execution policy or signing your scripts. In this article, we'll explore the causes of this error and provide detailed steps on how to fix it.

Understanding the Error

The Running scripts is disabled on this system error occurs because of PowerShell's execution policy. Execution policies are a set of rules that determine what PowerShell scripts can run on your system. The execution policy can be set to one of several levels, each with different levels of security. Here are the execution policy levels:

Execution Policy Levels

  1. Restricted: This is the default execution policy for Windows. It doesn't allow the execution of any scripts, regardless of their origin.
  2. AllSigned: Scripts must be digitally signed by a trusted publisher to run. This is a more secure policy and is often used in enterprise environments.
  3. RemoteSigned: Local scripts don't need to be signed, but any script downloaded from the internet must be signed by a trusted publisher.
  4. Unrestricted: This policy allows the execution of all scripts, whether signed or not. It is the least secure option.
  5. Bypass: This policy allows the execution of all scripts, but it still checks for the presence of a digital signature.
  6. Undefined: This means that no execution policy has been set. It is effectively the same as "Restricted."

The error message "Running scripts is disabled on this system" indicates that the current execution policy is set to "Restricted," preventing the execution of any PowerShell scripts.

Fixing the Error

To resolve the "Running scripts is disabled on this system" error, you can either change the execution policy or sign the script, depending on your specific needs and security considerations. Below are the steps to accomplish both:

Method 1: Changing the Execution Policy

  • Open PowerShell as an Administrator: To change the execution policy, you'll need administrative privileges. Right-click the PowerShell icon and choose Run as administrator.

  • Check the Current Execution Policy: You can check the current execution policy with the following command:

    Get-ExecutionPolicy
    

    You can also check all the Execution Policies that affect your session using the command below:

    Get-ExecutionPolicy -List
    

    Output:

    Img 1.png

  • Change the Execution Policy: To change the execution policy, use the Set-ExecutionPolicy cmdlet.

    Let's say you want to set the execution policy to RemoteSigned, which allows locally created scripts to run without being signed while requiring signed scripts from the internet, use the command below:

    Set-ExecutionPolicy RemoteSigned
    
  • Verify the New Execution Policy: You can verify that the execution policy has been changed using this command:

    Get-ExecutionPolicy
    

Method 2: Signing the Script

If you need to run a specific script that's not signed and you don't want to change the execution policy system-wide, you can sign the script with a trusted digital signature. Follow this tutorial to see how to sign your scripts.

How to Sign a PowerShell Script (a Step-By-Step Guide)
This article will give the readers a step-by-step explanation of how to sign a PowerShell script.

Conclusion

Encountering the "Running scripts is disabled on this system" error in PowerShell is a common issue, but it can be easily fixed by adjusting the execution policy or signing your scripts. The method you choose depends on your specific needs and security considerations. Be mindful of the security implications when changing the execution policy to allow the execution of unsigned scripts, and always use signed scripts for production or critical tasks to maintain a secure environment. By following the steps outlined in this article, you can successfully resolve this error and continue working with PowerShell effectively.

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.