为什么将 Powershell 设置为 set-executionpolicy remotesigned 失败?

mbx*_*mbx 15 powershell security-policy

使用 Win7-32​​bit 和 Powershell ISE,我尝试运行刚刚保存的脚本(假设包含一个简单的 cls)。我收到错误消息,通常的“get-help about_signing”建议禁止执行脚本。

当使用“set-executionpolicy remotesigned”来解决时,我得到了一个对话来验证我是否确定。但如果我接受另一个错误出现:

acces to registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" denied
    + set-executionpolicy <<<<  remotesigned
        + CategoryInfo          : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
Run Code Online (Sandbox Code Playgroud)

我该怎么做,以用户身份运行保存的脚本(或作为日常服务自动运行)?

Joh*_*don 15

您需要以管理员身份运行 powershell 来设置执行策略。

将其设置为 remotesigned 后,您就可以以普通用户身份运行 powershell。

  • 他的意思是你需要在提升的提示下运行。您可以右键单击任务栏或开始菜单中的 PowerShell 图标,然后选择“以管理员身份运行”。 (5认同)

mbx*_*mbx 7

只需转到控制面板 -> 管理工具 -> Windows PowerShell 模块(打开 powershell)并键入通常的“set-executionpolicy remotesigned”。就是这样。