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.

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. Milan Banjac 8 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?

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

  3. Maurice 8 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.

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

  5. Hays 8 years ago

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

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

  7. Robin 8 years ago

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

    to line 429 and it works

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

  9. Hays 8 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.

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

  11. PJ 8 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!

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

  13. Andre 7 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!

    • Mike 6 years ago

      Good one.

  14. Marton Csernak 7 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

  15. Neil Gascoigne 7 years ago

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

  16. Torben 6 years 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

  17. Glenn 6 years 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!

    • Author

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

  18. great work, Thank you both Malcolm McCaffery and Michael.

  19. Joar Guttormsen 5 years 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.

    • Author

      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.

  20. lumpycustard 5 years ago

    This was invaluable, saved me a lot of time and effort. Great work.

  21. Datatekniker 5 years ago

    Fantastic, been working on deploying .reg files via GPO.
    This did the work.
    Thanks a lot. !!!

  22. Nick Casagrande 5 years ago

    I was able to convert my odbc connection from reg to xml, no issues, but when pasting into GPO, it asks if I want to, i say ok, but then nothing shows up under data sources in the GPO.  could this be because the odbc driver does not exist on the domain controller or something?  i wouldnt think that would matter.

    • Author

      What happens if you use another registry key, like the one I used in the article?

      • Nick Casagrande 5 years ago

        weird, i got it working now!  ty so much!

  23. Abhishek Agarwal 5 years ago

    Does this converts entire registry info to xml?
    I mean does it even leave behind a single value?

     

    • Author

      If you are referring to the PowerShell script, it only converts the REG file you pass to XML.

      • Abhishek Agarwal 5 years ago

        On running the script, only the HKEY_USERS tree was stored. No other tree was stored.

        What to do?

  24. Jeff 5 years ago

    This is way more complicated than it needs to be. Microsoft has a very easy way of doing this by exporting an XML file, editing it, and then using GP to force it as the starting layout. After pulling my hair out trying to use your solution for a day I found this and had it done in a few minutes…

    https://docs.microsoft.com/en-us/windows/configuration/customize-and-export-start-layout

  25. Chad.w 5 years ago

    Fantastic! I did have you change “update” to “create” after the import as I was adding new keys.

Leave a reply

Please enclose code in pre tags

Your email address will not be published.

*

© 4sysops 2006 - 2022

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