报错详情
1 2 3 4 5 6 7 8 9
| PS C:\Users\kagari\Documents\script\wsl> .\portproxy.ps1 .\portproxy.ps1 : 无法加载文件 C:\Users\kagari\Documents\script\wsl\portproxy.ps1,因为在此系 统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中 的 about_Execution_Policies。 所在位置 行:1 字符: 1 + .\portproxy.ps1 + ~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [],PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
|
这个错误意味着执行策略很可能是 Restricted(默认设置)。
Restricted 执行策略不允许任何脚本运行。
AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。
执行get-executionpolicy查看执行策略
1 2
| PS C:\WINDOWS\system32> get-executionpolicy Restricted
|
解决方法
以管理员身份打开 PowerShell 执行 set-executionpolicy remotesigned
1 2 3 4 5 6 7 8
| PS C:\WINDOWS\system32> set-executionpolicy remotesigned
执行策略更改 执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略? [Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): y PS C:\WINDOWS\system32> get-executionpolicy RemoteSigned
|