- Poll: How reliable are ChatGPT and Bing Chat? - Tue, May 23 2023
- Pip install Boto3 - Thu, Mar 24 2022
- Install Boto3 (AWS SDK for Python) in Visual Studio Code (VS Code) on Windows - Wed, Feb 23 2022
The Windows Registry editor allows you to export a Registry key into a REG file. Unfortunately, you can’t just import the REG file into Group Policy Preferences; the Group Policy Editor only accepts XML files. Fortunately, Malcolm McCaffery wrote a PowerShell script that converts REG to XML.
Export REG file
To export a Registry key, launch the Registry editor (type regedit on the Start Screen), right-click the key, and then select Export from the context menu. The Registry editor will then prompt you to specify a file name for your REG file.
Export Registry key to REG file
Convert REG to XML
Malcolm’s PowerShell script to convert REG to XML contains a little bug that prevents the script from accepting input parameters. The author probably uploaded a version he used for testing. I modified the script, so you can use it right away. You can download the modified script here. If you just launch RegToXML.ps1, it will ask for the name of the REG and XML files. You can specify the input parameters like this:
.\RegToXML.ps1 c:\path\input.reg c:\path\output.xml
If the conversion is successful, you should see the XML output in the PowerShell console.
RegToXML supports the common Registry types:
- REG_DWORD
- REG_QWORD
- REG_EXPAND_SZ
- REG_MULTI_SZ
- REG_BINARY
- REG_SZ
Import into Group Policy Preferences
Importing the converted Registry path into Group Policy Preferences is simple, too, although not self-evident. You have to right-click the XML file in File Explorer and then copy it to the Windows clipboard.
Copy XML file to clipboard
Now, in the Group Policy Editor, navigate to User Configuration (or Computer Configuration) > Preferences > Windows Settings > Registry and right-click the white pane on the right. In the context menu, select Paste.
Import Registry key into Group Policy Preferences
The Group Policy Editor will insist that you confirm the import.
Confirm import
If the Group Policy Editor doesn’t like your XML file, you will get an error message.
The pasted document is invalid and will be ignored.
I know it is hard to be ignored. The only thing you can do now is try it again. Perhaps you just copied the wrong file. It is also possible that something went wrong during the REG to XML conversion.
You can also first create a folder and then paste the XML file. Right-click the Registry symbol, navigate to New, and then select Collection Item.
Collection Item
If the Group Policy Editor considers you worthy enough not to be ignored, after you paste the XML file you will see your Registry key with the complete folder structure of the Registry hive. You can then navigate to the keys to see whether the values are okay.
Imported Registry key
Notice that this method of deploying Registry settings with Group Policy Preferences is only something for absolute Registry geeks. The Registry settings can vary on different machine types with different configurations. Thus, you really have to understand what you are doing here.
If you are a Windows Taskbar expert, you have probably already noticed what Registry key I imported here. The Taskband key contains all the settings for the apps that you pinned to the Taskbar. However, deploying these Registry settings with Group Policy is not enough to configure the Taskbar properly. In one of my next posts, I will cover this topic in more detail.
Read the latest IT news and community updates!
Join our IT community and read articles without ads!
Do you want to write for 4sysops? We are looking for new authors.
Hi,
I converted a .reg file to .xml without any errors. But when I try to import it into the GPE I get “the pasted document is invalid and will be ignored” is there any way to find out what is invalid in the document?
Can anyone post a link to the xml format that the GPE can read? I cant find it anywhere.
Thanks!
You can follow the example in this post and then compare the XML file with yours. You might also want to check your XML file. The fact that there was no error message doesn’t ensure that everything worked.
Ah! I got it working now! The xml file was located on a network share, looks like the GPE doesn’t like that. Once I moved the file to a local drive it imported without a problem.
The error message could have shown a bit more info about what went wrong though! “computer says no” doesn’t really help.
Hope this helps others.
Thanks!
I get a LONG list of this
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:188 char:21
+ $xml.WriteattributeString(“name”,$valueName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:189 char:21
+ $xml.WriteattributeString(“default”,$default)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:190 char:21
+ $xml.WriteattributeString(“type”,”REG_SZ”)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:191 char:21
+ $xml.WriteattributeString(“displayDecimal”,”0″)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:192 char:21
+ $xml.WriteAttributeString(“value”,$value)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:193 char:21
+ $xml.WriteEndElement()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\regtoxml.ps1:194 char:21
+ $xml.WriteEndElement()
Hi Mark,
if remember correctly, that is because you need to specify the full path to both input and output file.
regards,
robert
Do you know how to include the “apply once and do not reapply” setting on each key in the XML file?
HI to all,
I’m looking for a tool that do exactly the opposite: convert GPO to .reg file. In my environment are some clients with windows 10 home so I want that pcs acts like others in domain (with w10 pro).
@Andrea
I don’t know if such a tools exist, but here in a Microsoft official Excel sheet, you have the full list of GPO/Registry matches:
https://www.microsoft.com/en-us/download/details.aspx?id=57464
Hello,
I need exactly the opposite. Convert GPO settings in an importable .reg file. This because I have domain clients and non domain clients, so I want client not in domain acts like others.
Manually create a .reg is very difficult because my GPOs do many changes, so identify what registry keys are modified in a domain client is not simple.
Do you know if exists a utility for this? That would be great.
Thank you
@andrea
You can try this one, which is only a viewer, but which is free:
Registry.Pol Viewer Utility
And this is a converter (probably not free):
Virtual Engine Toolkit
Virtual Engine Toolkit demo video
Thank you Luc, I’ll try
Does this script work for exports from HKEY_CLASSES_ROOT? Because I can't get it to work for love or money! I get a whole bunch of "The Writer is closed or in error state" yet when I check vssadmin list writers they all indicate stable and no error.
Richard, try love and money. Always works. 😉
Seriously, I think the script doesn't work with HKEY_CLASSES_ROOT and I somehow doubt that you will find the keys there you need for Group Policy Preferences. Make sure you located the correct registry keys.
I assure you I have the correct keys. It has to do with unhiding Photo Viewer on Win10. In any event, the CTO here found a site that does it for you:
https://www.runecasters.com.au/reg2gpp
Ran the REG file through the site, took the XML output and successfully added and tested via GPO.
Thank you for the quick response in any event.
Thank you very much for the Powershell script and detail instructions how to use it! It works for me as a charm.
Thanks saved a heap of time
Nice PS script, but it has a bug at QWORD. Loop runs only 7 times. One byte is lost.