A: Introduction
This article will discuss,
- A: Introduction
- B: What --- What is the Issue
- C: Why --- What is the Reason
- D: How to Fix:
- Temporary for the current session
- Permanently
B: What the issue is
When we run Angular in IDE either Visual Studio or VS Code, we can run the command in the built-in Terminal in the Environment, we might get error the first time, something like
- .ps1 is not digitally signed. The script will not execute on the system.
- Running script is disabled
For examples,
in Visual Studio IDE
in VS Code IDE
B: What is the Reason
This is due to PowerShell's execution policy. Go to the link as indicated https:/go.microsoft.com/fwlink/?LinkID=135170
PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the execution of malicious scripts.
On a Windows computer you can set an execution policy for the local computer, for the current user, or for a particular session. You can also use a Group Policy setting to set execution policies for computers and users.
Execution policies for the local computer and current user are stored in the registry. You don't need to set execution policies in your PowerShell profile. The execution policy for a particular session is stored only in memory and is lost when the session is closed.
The execution policy isn't a security system that restricts user actions. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally.
On non-Windows computers, the default execution policy is Unrestricted and cannot be changed. The Set-ExecutionPolicy
cmdlet is available, but PowerShell displays a console message that it's not supported. While Get-ExecutionPolicy
returns Unrestricted on non-Windows platforms, the behavior really matches Bypass because those platforms do not implement the Windows Security Zones.
C: How to Fix
Temporary solution for the current session:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Note: you need to run the command in admin mode.
After running the command, then run Angular app, it will be running without any issue:
This command sets the execution policy to bypass for only the current PowerShell session. After the window is closed, the next PowerShell session will open running with the default execution policy. “Bypass” means nothing is blocked and no warnings, prompts, or messages will be displayed.
Permanent solution
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Unrestricted
Note: you need to run the command in admin mode.
This will fix the issue forever for the whole machine,
References