Skip to main content

Resolving the “Script Execution Disabled” Error in PowerShell

 



If you’ve encountered the error message:

File C:\Program Files\nodejs\node_modules\npm\bin\npm.ps1 cannot be loaded because running scripts is disabled on this system.

This guide will help you resolve the issue step-by-step

Why Does This Error Occur?

By default, PowerShell restricts the execution of scripts for security reasons. This restriction is controlled by the Execution Policy, which determines which scripts can run on your system.

To enable script execution, we need to adjust this policy.

Step-by-Step Solution

1. Open PowerShell as Administrator

  • Right-click on the Start Menu or press Win + X.
  • Select Windows PowerShell (Admin).

This is necessary to make changes to your system’s settings.

2. Check the Current Execution Policy

Run the following command to see the current policy for the current user:

Get-ExecutionPolicy -Scope CurrentUser

You will likely see Restricted, which is the default policy.

3. Change the Execution Policy

To allow scripts to run, update the execution policy to RemoteSigned:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

Here’s what this policy means:

  • Local Scripts: Scripts created on your computer can run without any restrictions.
  • Remote Scripts: Scripts downloaded from the internet must be signed by a trusted publisher.

4. Verify the New Policy

To confirm the policy has been updated, run:

Get-ExecutionPolicy -Scope CurrentUser

It should now display RemoteSigned.

5. Retry Your Command

Close and reopen your terminal, then try running your npm command again:

npm init

The error should no longer appear, and you’ll be able to proceed with your project setup.

Important Notes

  • Security Considerations: Only change the execution policy for the current user (CurrentUser scope). This avoids system-wide changes and minimizes risks.
  • Reverting Changes: If needed, you can revert the policy back to Restricted later using:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Restricted

Conclusion

By following this guide, you’ve enabled PowerShell to run scripts safely, allowing tools like npm to function without issues. Let me know in the comments if you encounter any other roadblocks or have questions!

Comments

Popular posts from this blog

SOLID Principles – Simple Explanation for Beginners

 When I started learning object-oriented programming, I often wrote code that worked—but was hard to maintain or extend later. That’s when I came across the SOLID principles. These are five simple guidelines that help us write code that is: Easy to understand Easy to maintain Easy to scale In this blog, I’ll explain each principle in a simple way so you can understand the idea clearly. What are SOLID Principles? SOLID is a set of five design principles introduced by Robert C. Martin. Each letter represents one principle: S → Single Responsibility O → Open-Closed L → Liskov Substitution I → Interface Segregation D → Dependency Inversion S — Single Responsibility Principle (SRP) A class should have only one responsibility. Simple idea A class should do only one job. If a class has multiple responsibilities: It becomes harder to manage Changes in one part can affect other parts Example thinking Instead of: One class handling user data + logging + validation Split it into: One class fo...

Single Responsibility Principle – Simple Explanation with Example

When writing code, it’s common to put multiple responsibilities inside a single file or class. It might work at first, but over time it becomes difficult to manage and update. The Single Responsibility Principle (SRP) helps solve this. It is one of the core ideas from SOLID and focuses on keeping code simple and maintainable. What is Single Responsibility Principle? The idea is simple: A class should have only one responsibility. That means: It should do one job It should have only one reason to change Why This Matters When a class does too many things: Changes become risky Bugs become harder to track Code becomes difficult to understand Keeping responsibilities separate makes your code: Cleaner Easier to maintain Easier to scale Bad Example (Multiple Responsibilities in One Class) Let’s look at a class that handles everything: class UserService { validateUser(user) { if (!user.email) { console.log...

Oops Concepts : Inheritance In Java

When I first started learning Java, inheritance felt a bit confusing. But once I understood the basic idea, it became one of the easiest and most powerful concepts in Object-Oriented Programming (OOP). In this blog, I’ll explain inheritance in very simple English, so even if you're a beginner student or aspiring developer, you can understand it easily.  What is Inheritance in Java? In simple words, inheritance means reusing code from another class. I usually think of it like this: A child inherits features from parents Similarly, a class can inherit properties and methods from another class Definition: Inheritance is a mechanism where a child class gets properties and methods from a parent class. Key Terms (Very Important) Parent Class (Superclass) → The class that provides properties Child Class (Subclass) → The class that inherits those properties How Inheritance Works in Java Java uses the keyword:           extends Basic Syntax: This means the Chil...