The clipboard and PowerShell will speed up, but not blind.
Using GPP to add registry files is creepy and inconvenient - all these registry branches, key type, values ​​... Especially if branches and values ​​are pretty. But there are a couple lifehacks that can significantly speed up work with group policies.
You can, of course, hang a logon script with the command to import the registry branch. But this is not our method.
The first option is to create your own GPO template. This method is especially useful if you need to change the parameters of values ​​depending on the user. If you do not want to learn the principles of the formation of templates, you can simply export the "correct" reg-file and convert it into a template file using the REG_2_ADMXL.vbs script published in the Technet script gallery.
Suppose we want to make life easier for users by screwing several search engines to Internet Explorer as follows:
To do this, just prepare the registry file:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\W] @="http://ru.wikipedia.org/wiki/:Search?search=%s" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\Y] @="http://www.yandex.ru/yandsearch?rpt=rad&text=%s" [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\G] @="http://www.google.com/search?q=%s"
Convert it to a template with the following command:
cscript REG_2_ADMXL.vbs IE-search.reg Ru-ru IE-search.admx
The resulting template and folder with the language file we drop into the directory with the templates. Now our policy will appear in the GPO management snap-in.
Installed template.
The mechanism is not very convenient in terms of maintenance, but in principle it works. And do not manually drive anything.
Another option would be to use PowerShell cmdlets to work with GPOs. For example, to restore the context menu item “Send”, the set of cmdlets will be as follows:
Import-module -Name GroupPolicy New-GPO -Name SendTo Set-GPRegistryValue -Name "SendTo" -key "Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -ValueName SendTo -Type ExpandString -value "C:\Users\Default\AppData\Roaming\Microsoft\Windows\SendTo" Set-GPLink -Name SendTo -Target "ou=Users,dc=domain,dc=com" -LinkEnabled Yes
This is the option for just one key. If there are many keys, then for convenience you will have to reinvent the wheel and again convert the registry file into a set of PowerShell cmdlets.
You can read more about working with group policies and automating all of this in one of the previous articles, " Immersion in Templates and Taming Windows GPOs. " Well, I'll tell you about my favorite way.
As you may have noticed (I didn’t notice that very immediately), in the Group Policy Management snap-in, actions are available on objects, including standard clipboard operations.
Context menu in GPP registry settings.
If you copy an object to the clipboard and paste it, it turns out that this object is a file in xml format. This means that the file can be pre-formed and added to the snap-in without filling the fields manually.
For this, Malcolm McCaffery wrote a special script. It generates an xml file based on the exported registry file. The script can be taken in the author's blog .
In the script, the author has extra calls to the function Convert-Reg2Xml and an extra block of parameters. These errors are easily corrected during a test run via PowerShell ISE. Nevertheless, I just in case threw the corrected version on pastebin . There is also a fork of this script on github , and even an online service that does the same.
Using the script is extremely simple.
Convert-Reg2Xml -regPath input.reg -xmlPath output.xml
The resulting xml can even be dragged into the box for registry settings.
Let us examine a specific example. To begin with, we export the "correct" registry branch. In this example, we will make a policy to enable the display of hidden files, folders, and extensions, and at the same time we will make ctfmon.exe autostart for a smooth change of the layout.
The registry file is as follows:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] "Hidden"=dword:00000001 "HideFileExt"=dword:00000000 "ShowSuperHidden"=dword:00000001 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run] "Language Bar"=""ctfmon”=”CTFMON.EXE”
Convert it to xml. If you look at the resulting file, it will already be like this:
<?xml version="1.0" encoding="utf-8"?> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="HKEY_CURRENT_USER"> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="Software"> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="Microsoft"> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="Windows"> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="CurrentVersion"> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="Explorer"> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="Advanced"> <Registry clsid="{9CD4B2F4-923D-47f5-A062-E897DD1DAD50}" name="Hidden" descr="Imported Reg File" image="17"> <Properties action="U" hive="HKEY_CURRENT_USER" key="Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" name="Hidden" default="0" type="REG_DWORD" displayDecimal="0" value="00000001" /> </Registry> <Registry clsid="{9CD4B2F4-923D-47f5-A062-E897DD1DAD50}" name="HideFileExt" descr="Imported Reg File" image="17"> <Properties action="U" hive="HKEY_CURRENT_USER" key="Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" name="HideFileExt" default="0" type="REG_DWORD" displayDecimal="0" value="00000000" /> </Registry> <Registry clsid="{9CD4B2F4-923D-47f5-A062-E897DD1DAD50}" name="ShowSuperHidden" descr="Imported Reg File" image="17"> <Properties action="U" hive="HKEY_CURRENT_USER" key="Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" name="ShowSuperHidden" default="0" type="REG_DWORD" displayDecimal="0" value="00000001" /> </Registry> </Collection> </Collection> <Collection clsid="{53B533F5-224C-47e3-B01B-CA3B3F3FF4BF}" name="Run"> <Registry clsid="{9CD4B2F4-923D-47f5-A062-E897DD1DAD50}" name="Language Bar" descr="Imported Reg File" image="7"> <Properties action="U" hive="HKEY_CURRENT_USER" key="Software\Microsoft\Windows\CurrentVersion\Run" name="Language Bar" default="0" type="REG_SZ" displayDecimal="0" value=""ctfmon”=”CTFMON.EXE”" /> </Registry> </Collection> </Collection> </Collection> </Collection> </Collection> </Collection>
Now you can simply paste it into the registry settings. Such beauty will turn out:
Customized policy.
With proper skill, the process takes less time than reading this text.
For added convenience, you can add an item for registry files in the context menu to convert files in general in two clicks.
It will be enough to create a new type of action for objects of type regfile and set the path to the desired script. For your convenience, I put it, of course, in the registry file:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\regfile\shell\convert2xml] @="convert2xml" [HKEY_CURRENT_USER\Software\Classes\regfile\shell\convert2xml\command] @="powershell.exe -File C:\\temp\\script.ps1 %1"
The script path is set in the last line.
In order for the script to do this, you need to add the following lines to it:
$output=(Split-Path -Path $args[0]) + "\output.xml" Convert-Reg2Xml -regPath $args[0] -xmlPath $output
Now, when the context menu is called, another item will be displayed, when clicking on it, the xml file we need appears next to the registry file.
New context menu item.
Of course, for making simple changes to the registry of users and computers, such mechanisms are superfluous. But for setting up a large number of parameters, these life hacks are very convenient.
Source: https://habr.com/ru/post/419483/
All Articles