How to Resolve PowerShell Script Execution Policy Error for Angular CLI ?

1. Open PowerShell as Administrator

To address the script execution policy error, initiate PowerShell with administrative privileges. Right-click on the PowerShell icon and select "Run as Administrator."

2. Check the Current Execution Policy

Use the following command to inspect the current execution policy.

  • PowerShell command
  • Get-ExecutionPolicy

Get Execution Policy

3. Change the Execution Policy

If the current execution policy is too restrictive (e.g., "Restricted"), consider changing it to a more permissive setting like `RemoteSigned`:

  • PowerShell command
  • Set-ExecutionPolicy RemoteSigned

Remote Signed

Confirm the change by selecting 'Y' (Yes) when prompted.

4. Run Your Angular CLI Command Again

Retry your Angular CLI command after modifying the execution policy:

  • Angular Terminal
  • ng generate component test

Your Component will be created successfully with a test Component inside the app folder

Test

5. Restore the Original Execution Policy (Optional)

For security reasons, you can revert to the original execution policy after completing Angular CLI tasks:

  • PowerShell
  • Set-ExecutionPolicy Restricted

PowerShell

Confirm the change by selecting 'Y' (Yes) when prompted.

By adopting the `RemoteSigned` execution policy, you allow the execution of locally created scripts while mandating that downloaded scripts be signed by a trusted publisher.

This approach balances security and convenience, making it suitable for development purposes.

If you encounter any issues or have further questions, feel free to let me know, and I'll be glad to assist! Thank you for reading, and I hope this post has helped provide you with a better understanding of How to Resolve PowerShell Script Execution Policy Error for Angular CLI.

Keep coding, keep innovating, and keep pushing the boundaries of what's possible!

Happy Coding!