Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PowerShell refuses to run ng, npm or npx because script execution is disabled

Errorng : File C:\Users\<user>\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system.

Short answer

PowerShell blocks .ps1 files when the effective execution policy is Restricted, and the ng command is a .ps1 shim. Run Get-ExecutionPolicy -List to see which scope wins, then set RemoteSigned for CurrentUser. If a Group Policy sets it, you cannot override it; use ng.cmd or Command Prompt instead.

  • Applies to Windows 11, Windows PowerShell 5.1, PowerShell 7.5, Angular CLI 21, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every execution policy scope in precedence order. Read it top to bottom; the first scope that is not Undefined wins.

    Get-ExecutionPolicy -List
  2. 2Match what you see, then jump to its fix

    1. 1Every scope in the list shows Undefined, or the winning scope shows RestrictedNo policy is set, so Windows falls back to RestrictedFix
    2. 2MachinePolicy or UserPolicy is not Undefined, or Set-ExecutionPolicy succeeds but ng still failsGroup Policy sets the policy and overrides yoursFix
    3. 3You do not want a permanent policy change on this machineYou only need it for one sessionFix

What does the error look like?

  • ng : File C:\Users\<user>\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this system.
  • CategoryInfo : SecurityError: (:) [], PSSecurityException
  • FullyQualifiedErrorId : UnauthorizedAccess

Cause 1 of 3

No policy is set, so Windows falls back to Restricted

1Check

On a Windows client with nothing defined in any scope, the effective policy is Restricted, and Restricted allows single commands but never script files. The error names ng.ps1, which is a PowerShell script file, so the policy applies to it.

Get-ExecutionPolicy
Get-ExecutionPolicy -Scope CurrentUser

2Fix

Allow locally written scripts and signed downloaded scripts for your own user only. This needs no administrator window and does not touch other accounts.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

3Verify

The change is effective at once. Run the command again in the same window.

ng version

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

Group Policy sets the policy and overrides yours

1Check

A policy from Group Policy (the Turn on Script Execution setting) beats every scope you can set yourself. A command that changes the policy can succeed and still leave the effective policy unchanged.

Get-ExecutionPolicy -List
Get-ExecutionPolicy

2Fix

On a managed work PC, ask whoever runs the policy to change the Turn on Script Execution setting. Scopes you set yourself cannot override it, so changing them only wastes time.

Get-ExecutionPolicy -Scope MachinePolicy

3Verify

After the policy is changed, the winning scope in the list is no longer Restricted.

Get-ExecutionPolicy -List

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

You only need it for one session

1Check

The Process scope has the highest precedence and lives only in memory, so it disappears when the window closes.

Get-ExecutionPolicy -Scope Process

2Fix

Set the policy for this window only. Note that it still cannot override a Group Policy.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

3Verify

Run the command in the same window; a new window goes back to the old policy.

ng version

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Set RemoteSigned at CurrentUser scope once on a new machine instead of using Unrestricted or Bypass.
  • Avoid LocalMachine changes unless you must; they need an administrator window and affect every user.
  • On company laptops, check Get-ExecutionPolicy -List before blaming npm or the CLI.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.