简体   繁体   English

如何通过命令行更改组策略?

[英]How to change group policy via command line?

I want to update group policy in windows server using command line.我想使用命令行更新 windows 服务器中的group policy I don't want programatic way.我不想要程序化的方式。 I read this & this , and then tried delete registry keys based on the mapping of group policy and registry keys, but the group policy didn't got updated.我读了 this & this ,然后尝试根据组策略和注册表项的映射删除注册表项,但组策略没有更新。

Specifically, I want to set Computer Configuration\Administrative Templates\Windows Components\Windows Update\Configure Automatic Updates to Not configured in group policy.具体来说,我想在组策略中将Computer Configuration\Administrative Templates\Windows Components\Windows Update\Configure Automatic Updates设置为Not configured

So, I ran following commands,所以,我运行了以下命令,

C:\Windows\system32>reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v ScheduledInstallTime /f
The operation completed successfully.

C:\Windows\system32>reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v ScheduledInstallDay /f
The operation completed successfully.

C:\Windows\system32>reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v NoAutoUpdate /f
The operation completed successfully.

C:\Windows\system32>reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU /v AUOptions /f
The operation completed successfully.

But after that the group policy wasn't updated.但在那之后,组策略没有更新。 Do I need to run another command to propagate my registry changes to group policy?我是否需要运行另一个命令来将我的注册表更改传播到组策略? If yes, what is it?如果是,那是什么? What am I missing?我错过了什么?

I tried, gpupdate /force , it overrided my registry changes.我试过gpupdate /force ,它覆盖了我的注册表更改。 I need converse of this.我需要谈论这个。

How to change group policy from the command line? 如何从命令行更改组策略? Voila: 瞧:

LGPO.exe – Local Group Policy Object Utility, v1.0 LGPO.exe - 本地组策略对象实用程序,v1.0

For group policy objects in a domain, registry-based group policy settings can be configured from the command line using Powershell. 对于域中的组策略对象,可以使用Powershell从命令行配置基于注册表的组策略设置。 If you are not running on a domain controller, the Group Policy Management Console must be installed. 如果未在域控制器上运行,则必须安装组策略管理控制台。

See Group Policy Cmdlets in Windows PowerShell and in particular the Set-GPRegistryValue cmdlet . 请参阅Windows PowerShell中的组策略Cmdlet,特别是Set-GPRegistryValue cmdlet

You can of course run a Powershell command from the legacy command line, eg, 您当然可以从遗留命令行运行Powershell命令,例如,

powershell get-gpregistryvalue -Name gpo-name -Key HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -ValueName AUOptions

As far as I know, there is no command-line solution for local group policy. 据我所知,本地组策略没有命令行解决方案。 For local group policy, see Glenn's answer. 有关当地团体政策,请参阅Glenn的回答。

Set-GPRegistryValue is the way to go here. Set-GPRegistryValue是这里的方式。 The problem, which is common, is that you have the GP path and you need to raw data. 常见的问题是您拥有GP路径并且需要原始数据。 You can get the raw data (Keypath and value) from the settings spreadsheet, from the ADMX file (if administrative template setting) or from a free tool call registry.pol viewer from GPOGuy. 您可以从设置电子表格,ADMX文件(如果管理模板设置)或GPOGuy的免费工具调用registry.pol查看器中获取原始数据(Keypath和值)。

The commands you put up clean up registry data, these cmdlets don't do that. 您提供的命令会清理注册表数据,这些cmdlet不会这样做。 They add values to the registry.pol file (or registry.xml for GP Preference) stored in the GPO. 它们将值添加到GPO中存储的registry.pol文件(或GP Preference的registry.xml)中。 Those settings are then sent down to target systems and applied to registry. 然后将这些设置发送到目标系统并应用于注册表。 Also, for non-registry based policy and ability to automate settings across local policies search "Group Policy Automation" there is a solution out there you may want to look at. 此外,对于非基于注册表的策略以及跨本地策略自动化设置的能力搜索“组策略自动化”,您可能需要查看一个解决方案。

Group Policy Settings Reference for Windows and Windows Server Windows 和 Windows 服务器的组策略设置参考
https://www.microsoft.com/en-us/download/details.aspx?id=25250 https://download.microsoft.com/download/8/F/B/8FBD2E85-8852-45EC-8465-92756EBD9365/Windows10andWindowsServer2016PolicySettings.xlsx https://www.microsoft.com/en-us/download/details.aspx?id=25250 https://download.microsoft.com/download/8/F/B/8FBD2E85-8852-45EBD9365-89276EBD /Windows10和WindowsServer2016PolicySettings.xlsx

Mostly stored in the registry.主要存储在注册表中。 Find the reference above, then use reg.exe command line to modify them.找到上面的参考,然后使用 reg.exe 命令行来修改它们。

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

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