无法为CurrentUser设置Powershell ExecutionPolicy

这里是我正在运行的命令的一个示例:

PS C:\> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser Undefined LocalMachine Unrestricted PS C:\> Set-ExecutionPolicy Unrestricted -Scope CurrentUser PS C:\> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser Undefined LocalMachine Unrestricted 

我想将CurrentUser设置为Unrestricted ,但我似乎无法这样做。 我检查了这个MSDN文档中概述的组策略,但没有find任何configuration。

任何线索,我可以如何设置?

像所有其他人所说,这似乎是在Windows 10的预览版本中的错误。我通过简单地提供了-Force参数来得到它的工作。

设置本地计算机:

Set-ExecutionPolicy RemoteSigned -Force

当前用户设置:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

这似乎是Windows 10中的一个错误。我必须创build密钥HKEY_CURRENT_USER\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell然后在该密钥中创build一个名为ExecutionPolicy的string值,并使用数据Unrestricted 。 即使如此,我似乎无法修改registry而无需更改。

我没有看到我的安装Windows 10中的错误。我只是使用VMWare Workstation 11进行安装,并构build了一个虚拟机。 我跑了以下,没有做任何改变之前:

在这里输入图像描述

如果你想知道Windows 10的版本,我有: 10.0.10074

在更改执行策略之前,必须使用提升模式运行PowerShell

我有一个比OP更广泛的PowerShell政策问题,但是在这里和其他地方find答案的结合最终需要我的Win10周年纪念版正确地更新其政策:

1)确保此registry项存在,并设置为您希望允许的最低安全级别: HKEY_CURRENT_USER\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
Name:ExecutionPolicy Type: REG_SZ Data:Unrestricted
2)确保此registry项存在并设置为您要允许的最低安全级别: HKLM:\Software\Policies\Microsoft\Windows\PowerShell
Name:ExecutionPolicy Type: REG_SZ Data: Unrestricted
3)通过运行gpedit.msc更新您的组策略并导航到Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell
selectTurn on Script Execution ,然后selectTurn on Script Execution Enabled编辑policy setting ,并在下面的Execution Policy框中将其设置为Allow All Scripts

完成所有这些废话之后,您可以通过强制更新您的策略来使用ddcruver的回答,具体取决于您想要的内容。 如果您将策略设置为Unrestricted,则build议将所有从Get-ExecutionPolicy -List填充的设置设置为更严格的设置,如RemoteSigned ,因为恶意PowerShell脚本是导致基于内存的Windows恶意软件的主要原因之一。