admin管理员组

文章数量:1641322

cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft/fwlink/?LinkID=135170.

在powershell中打开angular-cli的时候,输入ng命令,收到了这个提示

ng : File C:\Users\ysu10\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/fwlink/?LinkID=135170.
At line:1 char:1
+ ng new
+ ~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

这个原因是由于脚本执行策略为严格模式,所以无法执行,可以通过

Get-ExecutionPolicy

来获取当前的脚本执行策略
默认为Restricted,要使脚本能够执行,需要修改为Unrestricted 或 Bypass.
相应的命令分别为

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force

如果设置为unrestricted,则如果执行从网上下载的未签名脚本时会询问用户。
如果设置为bypass,则会直接执行。

建议设置为unrestricted。

本文标签: runningloadedScriptsSystemdisabled