问题背景
运行Windows PowerShell(或者是VSCode Debuggable Package Manager)的时候出现了几行红字(类似问题也都差不多都是无法运行脚本)
. : 无法加载文件 C:\Users\vicky\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参
阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\vicky\Documents\WindowsPowerShell\profile.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
分析原因
在启动 Windows PowerShell 时,执行策略的默认设置是 Restricted。官方解释如下:
Restricted 执行策略不允许任何脚本运行。AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。
本主题说明如何运行所选未签名