Group Policy Preferences allow you to deploy Registry settings. If you have to deploy a large number of complicated Registry settings, you must convert a REG file into an XML file, which you can then import into Group Policy Preferences.
Avatar
Latest posts by Michael Pietroforte (see all)

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

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

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

Import Registry key into Group Policy Preferences

The Group Policy Editor will insist that you confirm the import.

Confirm 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

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

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

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.

50 Comments
  1. Avatar
    Robert 6 years ago

    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!

    • Avatar Author

      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.

  2. Avatar
    Robert 6 years ago

    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!

  3. Avatar
    Mark Mancini 5 years ago

    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()

  4. Avatar
    Robert 5 years ago

    Hi Mark,

    if remember correctly, that is because you need to specify the full path to both input and output file.

    regards,

    robert

  5. Avatar
    seth gregory 5 years ago

    Do you know how to include the “apply once and do not reapply” setting on each key in the XML file?

  6. Avatar
    andrea cappini 5 years ago

    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).

     

  7. Avatar

    @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

  8. Avatar
    andrea cappini 5 years ago

    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

  9. Avatar
    andrea cappini 5 years ago

    Thank you Luc, I’ll try

  10. Avatar
    Richard 4 years ago

    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.

    • Avatar Author

      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.

  11. Avatar
    Richard 4 years ago

    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.

    avatar
  12. Avatar
    Mich 4 years ago

    Thank you very much for the Powershell script and detail instructions how to use it! It works for me as a charm.

  13. Avatar
    Stewart 3 years ago

    Thanks saved a heap of time

  14. Avatar
    User 2 years ago

    Nice PS script, but it has a bug at QWORD. Loop runs only 7 times. One byte is lost.

                       # unreverse QWORD for settings.xml format
                        for ($i = $tempValue.Length -2;$i -gt 0;$i-=2)
                        {
                            $value+=$tempValue.Substring($i,2)
                        }
    
     
    
    Fix:              for ($i = $tempValue.Length ;$i -gt 0;$i-=2)
                        {
                            $value+=$tempValue.Substring($i-2,2)
                        }

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account