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.

Michael Pietroforte

Michael Pietroforte is the founder and editor of 4sysops. He is a Microsoft Most Valuable Professional (MVP) with more than 30 years of experience in IT management and system administration.

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:

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.

Win the monthly 4sysops member prize for IT pros

Share
0

22 Comments
  1. Milan Banjac 3 years ago

    In "Copy XML file to clipboard" image, you are actually copying a .reg file. Is it a mistake, or you did it on purpose to show what happens if GPO Editor "doesn't like" the XML file that is pasted?

    0

  2. Michael Pietroforte 3 years ago

    Well spotted! I replaced the screenshot now. Thanks for the hint!

    0

  3. Maurice 3 years ago

    I think your script that should fix the issue is still causing problems.
    When you run it you get an error that it cannot find the function "Convert-Reg2XML".

    I replaced line 12: Convert-Reg2XML -regPath $regPath -xmlPath $xmlPath
    to the bottom of the script and then it worked.

    0

  4. Michael Pietroforte 3 years ago

    Oops, seems I also uploaded the wrong version. I corrected the typo now. Thanks a lot for the hint!

    0

  5. Hays 3 years ago

    Hi Michael, Are you sure you uploaded the correct script without the typo because I'm having the same issue as Maurice.

    0

  6. Michael Pietroforte 3 years ago

    Hays, I just downloaded the script and tried it. Works fine. What error message do you get?

    0

  7. Robin 3 years ago

    i also moved line 12 (Convert-Reg2Xml -regPath $regPath -xmlPath $xmlPath)

    to line 429 and it works

    0

  8. Michael Pietroforte 3 years ago

    It would be helpful if you guys tell me what is not working with the script I uploaded, so I can search for a bug. When I start it it works perfectly fine. No need to move any lines. Just start the script and it will ask for the regPath.

    0

  9. Hays 3 years ago

    Hi Michael, I just get the same function error as Maurice - cannot find the function “Convert-Reg2XML”. I have not tried moving line 12 as Robin stated though.

    0

  10. Michael Pietroforte 3 years ago

    Hays, thanks! I think I got it now. I started the script in PowerShell ISE through the Run script button. This loads the function before the scripts hits the line that calls the function. This doesn't work if you start the script from the console. That's why the function call should be at the end of the script as Robin correctly noted. Seems I have been scripting too much in PHP lately. I hope it works now.

    0

  11. PJ 3 years ago

    Input is a bit confusing at first for two reasons; first is you mention that its a one-liner in your article, but when I run the script it asks for the reg file location first, and then the output file location on the second line. Second, is that it is asking for the file "Location", so if i have the file located on my desktop and just input the path to my desktop, the script wont run properly as its actually looking for the file name as well, so that is a bit misleading. Other than that worked like a charm. Thank you!

    0

  12. Michael Pietroforte 3 years ago

    PJ, you are right. The script requires you to specify the full paths to the files. Something like this should work:

    .\RegToXML.ps1 c:\path\input.reg c:\path\output.xml

    I changed the text accordingly. Thanks for the hint.

    0

  13. Andre 2 years ago

    FYI, I was getting the invalid document error and the problem was that I had the xml file on a network share. I moved the xml to a local folder and then was able to copy and paste it. Hope this helps!

    1+

    • Mike 4 months ago

      Good one.

      0

  14. Marton Csernak 2 years ago

    Hi Michael,

    Thank you for your work, nice script! 🙂

    We tried to convert the following .reg but unfortunately it's not working properly:

    http://cdn2.howtogeek.com/wp-content/uploads/2015/08/Activate-Windows-Photo-Viewer-on-Windows-10.zip

    4+

  15. Neil Gascoigne 2 years ago

    Rock and roll! That just saved me half an hour 🙂

    0

  16. Torben 12 months ago

    That static guid being used in the PS script, is that in anyway related to how the policy engines considers what subsequent changes to a GPP entry have to be updated or ignored?

    If it is related, and I want to 'update' the same regkey/setting with this script, does the GP engine recognize the new value or does it just ignore it base on the GUID being the same?

    hope that made sense.
    thanks

    0

  17. Glenn 4 months ago

    Michael,

    Just wanted to let you know how valuable this tool is for me.

    My company is using PuTTY to make SSH connections to what will ultimately be over a thousand network devices. PuTTY can store sessions, but does in via registry items in HKCU. Your script has enabled me to make all the session settings on one machine, export the registry, CONVERT IT TO XML and create a GPO for all management users to have the session information.

    Your script worked right out of the box.

    Incredible time saver!

    0

    • Author
      Michael Pietroforte 4 months ago

      Glenn, I am glad that it worked well. However this is not my script. I only modified Malcolm McCaffery's script a little.

      0

  18. Douglas Camus 4 months ago

    great work, Thank you both Malcolm McCaffery and Michael.

    0

  19. Joar Guttormsen 3 weeks ago

    Im getting this error when I try to convert a reg to xml

    You cannot call a method on a null-valued expression.
    At C:\temp\RegToXML.ps1:54 char:9
    + if ($line.StartsWith("["))
    + ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    I dont know much about Powershell. So I have no idea what to do.

    0

    • Author
      Michael Pietroforte 3 weeks ago

      Sounds as if the script can't find the reg file. Make sure to pass the full path to the reg file and the XML file as described in the example. If this doesn't work, try with a simple reg file to make sure that you pass the input correctly.

      0

Leave a reply

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

*

CONTACT US

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

Sending
© 4sysops 2006 - 2017

Log in with your credentials

or    

Forgot your details?

Create Account