gpt4 book ai didi

powershell - 运行任何 powershell 脚本时出现 Set-ExecutionPolicy 错误

转载 作者:行者123 更新时间:2023-12-05 02:11:40 25 4
gpt4 key购买 nike

我在运行任何 powershell 脚本时遇到以下错误。它只发生在一个客户的服务器上。我不确定是什么触发了这个命令。

如果我将此注册表项从 RemoteSignedto 更改为 ByPass,错误就会消失。

Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass

例如我有下面一行简单的脚本。

Read-Host -Prompt "Hit Enter to exit"
Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by
a policy defined at a more specific scope. Due to the override, your shell will retain its current effective
execution policy of RemoteSigned. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more
information please see "Get-Help Set-ExecutionPolicy".
At line:1 char:46
+ if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
+ FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
Result from Get-ExecutionPolicy -List

Scope ExecutionPolicy
----- ---------------
MachinePolicy RemoteSigned
UserPolicy RemoteSigned
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted

最佳答案

您需要以管理员身份运行,然后尝试Set-ExecutionPolicy..

或者您也可以通过这种方式运行 powershell:

powershell.exe -ExecutionPolicy bypass

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

关于powershell - 运行任何 powershell 脚本时出现 Set-ExecutionPolicy 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57149955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com