powershell - 运行任何 powershell 脚本时出现 Set-ExecutionPolicy 错误
问题描述
运行任何 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
解决方案
你需要Run as Administrator
然后尝试Set-ExecutionPolicy
..
或者您也可以通过这种方式运行 powershell:
powershell.exe -ExecutionPolicy bypass
或者
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
推荐阅读
- r - 对于层次聚类,如何在 R 中的每个聚类中找到“中心”
- c - 如何解决“右手操作数无效”错误?
- excel - 列表框值为空
- python - 如何将 django 中表单的动态字段插入数据库
- python - UnboundLocalError:在 Flask 中赋值之前引用了局部变量“dna”
- java - LWJGL - 循环冻结的原因?
- visual-studio-code - 有没有办法根据当前打开的目录更改 vs 代码设置?
- python - 如何增加猜测次数?
- r - R 中的 getSymbols 已弃用警告消息“indexClass<-”
- c# - 如何向 IdentityServer LogoutRequest 模型添加参数?