How to fix "running scripts is disabled on this system"?

Viewed 35897

When I try to run ionic commands like ionic serve on the VS Code terminal, it gives the following error.

How can I fix this?

ionic : File C:\Users\Lakshan\AppData\Roaming\npm\ionic.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
+ ~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
4 Answers

I found a way to fix this error.

It is as follows:

  1. First, Open PowerShell with Run as Administrator.
  2. Then, run this command in PowerShell
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
    
  3. After that type Y and press Enter.

This is because of Execution Policy. This defines how powershell scripts will run.

In Default windows desktops, it is Restricted, not allowing any scripts (signed or unsigned) only interactive sessions.

So best is you set using RemoteSigned (Default on Windows Server) letting only signed scripts from remote and unsigned in local to run, but Unrestriced is insecure lettting all scripts to run.

To set run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned as administrator.

To Bypass this you need to change the Execution policy. Type this into your terminal.

Set-ExecutionPolicy -Scope CurrentUser

then it will prompt you to supply a value at which point you can set Bypass / RemoteSigned or Restricted.

cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: "RemoteSigned" or "Bypass" or "Restricted".

This code will fix it:

Set-ExecutionPolicy RemoteSigned –Scope Process
Related