PowerShell refuses to run ng, npm or npx because script execution is disabled
ng : 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.
Fix it fast
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 -List2Match what you see, then jump to its fix
- 1
Every scope in the list shows Undefined, or the winning scope shows RestrictedNo policy is set, so Windows falls back to RestrictedFix - 2
MachinePolicy or UserPolicy is not Undefined, or Set-ExecutionPolicy succeeds but ng still failsGroup Policy sets the policy and overrides yoursFix - 3
You do not want a permanent policy change on this machineYou only need it for one sessionFix
- 1
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: (:) [], PSSecurityExceptionFullyQualifiedErrorId : 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 CurrentUser2Fix
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 CurrentUser3Verify
The change is effective at once. Run the command again in the same window.
ng versionConfirmed by learn.microsoft.com
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-ExecutionPolicy2Fix
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 MachinePolicy3Verify
After the policy is changed, the winning scope in the list is no longer Restricted.
Get-ExecutionPolicy -ListConfirmed by learn.microsoft.com
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 Process2Fix
Set the policy for this window only. Note that it still cannot override a Group Policy.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process3Verify
Run the command in the same window; a new window goes back to the old policy.
ng versionConfirmed by learn.microsoft.com
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
The terminal says 'ng: command not found' after installing Angular
zsh: command not found: ng
The shell finds ng only if the Angular CLI is installed and npm's global bin folder is on your PATH.
3 causes, each with a fixBack 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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix