vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)

vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)

vue : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies

Solution

该问题的solution就是通过powershell去解除Execution_Policies(运行策略)的限制。

  1. 开始菜单或者小娜搜索输入powershell,powershell ISE或者直接powershell命令行都ok,选择 以管理员身份运行
    vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)
  2. 输入 get-ExecutionPolicy 查看当前策略,一般默认是:Restricted 受限制的vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)
  3. 输入 set-ExecutionPolicy RemoteSigned 设置为RemoteSigned 远程签名
    vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)
  4. 输入get-ExecutionPolicy -List 查看当前所有Scope的ExecutionPolicy vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)
  5. 重新运行需要运行的vue ui脚本,选择允许防火墙。搞定!
    vue: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\vue.ps1,因为在此系统上`禁止运行脚本`。(powershell运行策略设置)

扩展阅读:PowerShell execution policies

Enforcement of these policies only occurs on Windows platforms. The PowerShell execution policies are as follows:

这些策略仅在Windows平台上执行。 PowerShell执行策略如下:

AllSigned:信任签名

  • Scripts can run.
  • Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
  • Prompts you before running scripts from publishers that you haven’t yet classified as trusted or untrusted.
  • Risks running signed, but malicious, scripts.
  • 脚本可以运行。
  • 要求所有脚本和配置文件均由受信任的发布者签名,包括您在本地计算机上编写的脚本。
  • 在运行尚未归类为受信任或不受信任的发布者的脚本之前提示您。
  • 运行带有签名但有恶意的脚本有风险。

Bypass:分流

  • Nothing is blocked and there are no warnings or prompts.
  • This execution policy is designed for configurations in which a PowerShell script is built in to a larger application or for configurations in which PowerShell is the foundation for a program that has its own security model.

-没有任何障碍,也没有警告或提示。
-此执行策略设计用于将PowerShell脚本内置到更大的应用程序中的配置,或者用于以PowerShell为具有自己的安全模型的程序的基础的配置。

Default:默认

那么windows系统默认的策略是:
Sets the default execution policy.

  • Restricted for Windows clients/customer version.
  • RemoteSigned for Windows servers.

RemoteSigned:远程签证

The default execution policy for Windows server computers.

  • Scripts can run.
  • Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the internet which includes email and instant messaging programs.
  • Doesn’t require digital signatures on scripts that are written on the local computer and not downloaded from the internet.
  • Runs scripts that are downloaded from the internet and not signed, if the scripts are unblocked, such as by using the Unblock-File cmdlet.
  • Risks running unsigned scripts from sources other than the internet and signed scripts that could be malicious.

Windows Server服务器的默认执行策略。(但是为什么个人系统还要自己设置=。=)

  • 脚本可以运行。
  • 需要从可信任的发布者处获得从互联网上下载的脚本和配置文件的数字签名,其中包括电子邮件和即时消息传递程序。
  • 不需要在本地计算机上编写且未从Internet下载的脚本上进行数字签名。
    运行脚本,这些脚本是从Internet下载的且未签名的脚本(如果已解除阻止),例如使用Unblock-File cmdlet。
  • 可能会运行来自Internet以外的其他来源的未签名脚本和可能有害的已签名脚本。

Restricted:受限制模式

  • The default execution policy for Windows client computers.
  • Permits individual commands, but does not allow scripts.
  • Prevents running of all script files, including formatting and configuration files (.ps1xml), module script files (.psm1), and PowerShell profiles (.ps1).

Windows客户端计算机的默认执行策略。(=。=为什么限制个人而不是服务器?!)

  • 允许使用单个命令,但不允许使用脚本。
  • 阻止运行所有脚本文件,包括格式和配置文件(.ps1xml),模块脚本文件(.psm1)和PowerShell配置文件(.ps1)。

Undefined:未定义

  • There is no execution policy set in the current scope.
  • If the execution policy in all scopes is Undefined, the effective execution policy is Restricted for Windows clients and RemoteSigned for Windows Server.
  • 当前范围内未设置执行策略
  • 如果所有作用域中的执行策略均为未定义,则对于Windows客户端,有效的执行策略为“受限”;对于Windows Server,则为RemoteSigned。

Unrestricted:无限制

  • The default execution policy for non-Windows computers and cannot be changed.
  • Unsigned scripts can run. There is a risk of running malicious scripts.
  • Warns the user before running scripts and configuration files that are not from the local intranet zone.
  • 非Windows计算机默认执行策略,不能更改。
  • 未签名的脚本可以运行。 有运行恶意脚本的风险。
  • 在运行非本地Intranet区域中的脚本和配置文件之前警告用户。