Skip to content

Fixing "Running Scripts is Disabled on This System" Error in Windows

Problem Statement

When attempting to run PowerShell scripts or commands that execute scripts (such as those from npm packages like Ionic, Angular CLI, or other development tools), you may encounter the following error:

ionic : File C:\Users\Lakshan\AppData\Roaming\npm\ionic.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see 
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

This error occurs because Windows PowerShell has security policies (Execution Policies) that restrict script execution by default to prevent malicious scripts from running unintentionally.

Understanding PowerShell Execution Policies

PowerShell execution policies are security measures that determine which scripts can run on your system:

Execution Policy Levels

  • Restricted: No scripts can run (default on Windows clients)
  • RemoteSigned: Local scripts run, but remote scripts must be signed
  • Unrestricted: All scripts can run (security risk)
  • Bypass: No restrictions and no warnings

Solutions

For permanent resolution, change the execution policy system-wide:

  1. Open PowerShell as Administrator (right-click PowerShell and select "Run as administrator")
  2. Run the following command:
    powershell
    Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
  3. Confirm with Y when prompted

This sets the policy to RemoteSigned, allowing local scripts to run while requiring digital signatures for remote scripts, providing a good balance of security and functionality.

2. Set User-Specific Execution Policy

If you don't have administrator privileges, set the policy for your current user only:

powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

3. Temporary Solution for Current Session

For a one-time fix that only affects your current PowerShell session:

powershell
Set-ExecutionPolicy RemoteSigned -Scope Process

This approach doesn't modify system settings and reverts when you close the terminal.

4. Interactive Setup

If you prefer being prompted for the execution policy value:

powershell
Set-ExecutionPolicy -Scope CurrentUser

You'll then be prompted to enter your preferred policy level (e.g., RemoteSigned, Bypass, or Restricted).

Security Considerations

  • Avoid using Unrestricted as it poses significant security risks
  • Avoid using Bypass for regular use as it disables all security warnings
  • RemoteSigned is Microsoft's recommended setting for most scenarios

Best Practices for Developers

  1. Use the minimum required permissions - Only elevate to administrator when necessary
  2. Consider scope carefully - User-specific changes (CurrentUser) are often sufficient
  3. Test scripts locally before deploying to production environments
  4. Sign your scripts if distributing them to others for professional use

Alternative Approach: Run with Bypass Flag

If you prefer not to change your system's execution policy, you can run specific scripts with a bypass flag:

powershell
powershell -ExecutionPolicy Bypass -File your-script.ps1

This executes the specific script without modifying your system's execution policies.

Verifying Current Execution Policies

To check your current execution policies:

powershell
Get-ExecutionPolicy -List

This displays the execution policies at different scope levels (MachinePolicy, UserPolicy, Process, CurrentUser, LocalMachine).

Conclusion

The "running scripts is disabled on this system" error is a security feature, not a bug. For most development scenarios, setting the execution policy to RemoteSigned provides the right balance between security and functionality. Choose the solution that best fits your security requirements and administrative access level.