简体   繁体   English

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

[英]Getting Set-ExecutionPolicy error while running any powershell script

I am getting below error while running any powershell script. 运行任何Powershell脚本时出现以下错误。 It's happening on only one of the client's servers. 它仅在客户端的一台服务器上发生。 I am not sure what is triggering this command. 我不确定是什么触发了此命令。

If I change this registry key from RemoteSignedto to ByPass error goes away. 如果我将此注册表项从RemoteSignedto更改为ByPass,错误将消失。

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

For example I have below simple script of one line. 例如,我下面有一行简单的脚本。

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

You need to Run as Administrator and then try to Set-ExecutionPolicy .. 您需要以Run as Administrator身份Run as Administrator ,然后尝试Set-ExecutionPolicy ..

or you can run powershell by this way also : 或者您也可以通过这种方式运行powershell:

powershell.exe -ExecutionPolicy bypass

or 要么

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM