运行Powershell脚本提示“因为在此系统上禁止运行脚本”解决办法

PS C:\Users\HP> cd .\Desktop\
PS C:\Users\HP\Desktop> '"Hello,Powershell Script"' > MyScript.ps1
PS C:\Users\HP\Desktop> .\MyScript.ps1
.\MyScript.ps1 : 无法加载文件 C:\Users\HP\Desktop\MyScript.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:
/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ .\MyScript.ps1
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\HP\Desktop> get-ExecutionPolicy
Restricted
PS C:\Users\HP\Desktop> set-ExecutionPolicy

位于命令管道位置 1 的 cmdlet Set-ExecutionPolicy
请为以下参数提供值:
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:\Users\HP\Desktop> .\MyScript.ps1
Hello,Powershell Script
PS C:\Users\HP\Desktop>

运行get-ExecutionPolicy提示Restricted说明是被限制了

运行set-ExecutionPolicy,输入remotesigned,再输入Y

问题解决

猜你喜欢

转载自blog.csdn.net/lildkdkdkjf/article/details/125535234