How To Fix Error PS1 Can Not Be Loaded Because Running Scripts Is Disabled On This System In Angular

Introduction 

When you have to run your Angular project or any ng command, you may see that the system shows the below error: 

ng: File C:\Users\admin\AppData\Roaming\npm\ng.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

+ ng --v

+ ~~

+ CategoryInfo : SecurityError: (:) [], PSSecurityException

+ FullyQualifiedErrorId : unauthorized access

Solution

This error occurs when your system has disabled the running script and your system is can’t accept the ng commands. This error occurs due to security reasons and won't let the script be executed on your system without your approval. Then you have to open the PowerShell with administrative rights.

To solve this problem, you need to follow a few steps:

Step 1

First, you have to need to open the command prompt and run this command.

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

When you run this command, you can see that your system has set all policies for the current user as remotely. It will take few seconds to complete this process.

The image will be shown like below.

How To Fix PS1 Can Not Be Loaded Because Running Scripts Is Disabled On This System In Angular 

Now you have to go to the next step.

Step 2

Now you have to run the second command on your system. This command is:

Get-ExecutionPolicy

When you have run this command your system has a show "RemoteSigned". If you have received this message, then your problem will be solved. Now you have to go to the next step to view the list of policy which policy has been updated by the last commands.

The image will be shown as below:

How To Fix PS1 Can Not Be Loaded Because Running Scripts Is Disabled On This System In Angular

Step 3

To view their policy, you need to run this command in your command prompt:

Get-ExecutionPolicy -list  

When you run this command, a few policies are shown on your monitor screen. These policies are:

How To Fix PS1 Can Not Be Loaded Because Running Scripts Is Disabled On This System In Angular

Scope ExecutionPolicy
----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine Undefined
CurrentUser RemoteSigned
LocalMachine Undefined

Now you can see your system execution policy list. You have successfully solved your problem. Now you need to go to the command prompt and check that your problem is solved.

Now I run an ng command in my command prompt. This command is "ng --version". To check my CLI version. When I run it, the ng command the output will be shown like this:

OUTPUT

How To Fix PS1 Can Not Be Loaded Because Running Scripts Is Disabled On This System In Angular

You can see that the ng command has been run successfully. Now my problem is solved.  

I hope you enjoyed this article. To learn more about Angular, follow me, and to learn more technology, follow C# Corner.


Similar Articles