英文:
change execution policy and enable execution of PowerShell scripts
问题 {#heading}
如何更改允许在我的计算机上运行PowerShell脚本的策略?
我已尝试检查下面描述的解决方案:
我已更改以下位置的设置:
MMC(计算机配置 -> 管理模板 -> Windows 组件)
和
regedit(HKEY_LOCAL_MACHINE -> SOFTWARE -> Policies -> Microsoft -> Windows -> Powershell)
但是我一直在附加的屏幕上收到以下错误:
Set-ExecutionPolicy:Windows PowerShell已成功更新您的执行策略,但该设置被更具体范围定义的策略覆盖。由于覆盖,您的Shell将保留其当前的有效执行策略RemoteSigned。键入"Get-ExecutionPolicy -List"以查看您的执行策略设置。有关更多信息,请参阅"Get-Help Set-ExecutionPolicy"。
在第1行第46个字符:+ ... -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'C ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : PermissionDenied:(:) [Set-ExecutionPolicy],SecurityException
- FullyQualifiedErrorId:ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
[HKEY_LOCAL_MACHINE -> SOFTWARE -> Policies -> Microsoft -> Windows -> Powershell] 已更改为 "ByPass"
计算机配置 -> 管理模板 -> Windows 组件
打开脚本执行:已启用
执行策略:允许所有脚本
英文:
How can I change the policy that will allow me to run the PowerShell script on my machine?
PowerShell screen
I have tried checking the solution described there:
I changed the settings in
MMC (Computer Configuration -> Administrative Templates -> Windows Components)
and
regedit (HKEY_LOCAL_MACHINE -> SOFTWARE -> Policies -> Microsoft -> Windows -> Powershell)
but all the time I am getting that error on the attached screen
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 p
p lease see "Get-Help Set-ExecutionPolicy".
At line:1 char:46
-
... -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'C ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
- FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
HKEY_LOCAL_MACHINE -> SOFTWARE -> Policies -> Microsoft -> Windows -> Powershell
changed to "ByPass"
Computer Configuration -> Administrative Templates -> Windows Components
Turn Script execution: enabled
Execution policy: allow all scripts
答案1 {#1}
得分: 1
尝试这个并逐步进行。
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
你可以尝试其他范围的值。
Get-Help Set-ExecutionPolicy -Parameter scope
获取该参数列出的枚举值:
[Microsoft.PowerShell.ExecutionPolicyScope]::GetValues([Microsoft.PowerShell.ExecutionPolicyScope])
英文:
Try this and work up.
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
You can try other values for scope.
Get-Help Set-ExecutionPolicy -Parameter scope
Get the values for the enum listed for that parametr:
[Microsoft.PowerShell.ExecutionPolicyScope]::GetValues([Microsoft.PowerShell.ExecutionPolicyScope])
答案2 {#2}
得分: 0
-
通过 GPO(组策略对象)(如您问题中描述的通过 MMC)成功更新了您的脚本执行策略。
-
基于 GPO 的执行策略在所有可设置策略的范围中具有最高的优先级;
Get-ExecutionPolicy -List
按优先级降序显示各个范围。 -
您的错误消息显示了尝试设置 当前进程 (
-Scope Process
) 的执行策略。 -
因为进程范围内的执行策略会被 GPO 基于的执行策略 覆盖 ,所以进程级别的尝试是 无效 的,这就是错误消息试图告诉您的内容。
-
如果 GPO 基于的执行策略仍然足够宽松以允许您运行脚本,您可以 忽略 这个错误,但我怀疑进程级别尝试设置执行策略是因为通过文件资源管理器上下文菜单运行脚本而导致的,很不幸,该调用命令是这样定义的。
- 您可以尝试通过注册表 (
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\0\Command
) 修改调用命令,并将其中的Set-ExecutionPolicy
调用移除。
- 您可以尝试通过注册表 (
英文:
-
You've (successfully) updated your script execution policy via a GPO (Group Policy Object; via MMC, as described in your question).
-
GPO-based execution policies have the highest precedence among all the scopes in which you can set a policy;
Get-ExecutionPolicy -List
shows the scopes in descending order of precedence. -
Your error message shows an attempt to set the execution policy for the current process (
-Scope Process
). -
Because an execution policy in the process scope is overridden by GPO-based execution policies, the process-level attempt is ineffective, and that's what the error message is trying to tell you.
-
You can ignore the error if the GPO-based execution policy is still permissive enough to allow you to run your script, but I suspect that the process-level attempt to set the execution policy stems from running your scripts via File Explorer's context menu, whose invocation command is - unfortunately - defined that way.
- You can try to modify the invocation command via the registry (
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\0\Command
) and remove theSet-ExecutionPolicy
call from it.
- You can try to modify the invocation command via the registry (