GitHub - janweis/Reg-To-Xml-GPP-Converter: 🔄 Convert .reg files to GPP-compatible XML for easy deployment via Group Policy Preferences. · GitHub
Skip to content

janweis/Reg-To-Xml-GPP-Converter

Folders and files

Repository files navigation

Reg-To-XML GPP Converter

Turns a Windows .reg export into the XML that Group Policy Preferences actually uses, so you can drop a pile of registry settings into a GPO without recreating every value by hand.

The usual story: you configure an application on a reference machine, export the relevant keys with regedit, and then realise GPMC wants you to click each value back in one at a time. This script skips that part.

What it does

It reads a .reg file and writes a GPP registry file next to it (<name>.reg.xml). The output follows Microsoft's GPP registry format ([MS-GPPREF]), so the Group Policy editor takes it as-is.

Value types it understands:

  • REG_SZ
  • REG_EXPAND_SZ
  • REG_MULTI_SZ
  • REG_BINARY
  • REG_DWORD
  • REG_QWORD

REG_NONE, REG_LINK and REG_DWORD_BIG_ENDIAN aren't supported by GPP itself, so those entries are skipped and you get a warning naming the line that was dropped.

Requirements

  • PowerShell 3.0 or newer (every supported Windows already has this)
  • A .reg file in the normal regedit export format (the one starting with Windows Registry Editor Version 5.00)

Using it

The simple case:

.\Convert-RegToGppXml.ps1 -FilePath "C:\Temp\MyApp.reg"

That gives you C:\Temp\MyApp.reg.xml in the same folder.

Paths with spaces work, and you can hand it more than one file at once:

.\Convert-RegToGppXml.ps1 -FilePath "C:\Temp\App settings.reg", "C:\Temp\Other.reg"

Everything is written as an Update action by default. If you need a different one, use -ActionType:

.\Convert-RegToGppXml.ps1 -FilePath "C:\Temp\MyApp.reg" -ActionType Replace

Parameters

Parameter Required Values Default Notes
-FilePath yes one or more paths to .reg files
-ActionType no Create, Update, Delete, Replace Update how GPP applies each entry
-BypassErrors no switch off writes bypassErrors="1" so one bad value doesn't stop the rest on the client

Getting the XML into a GPO

The output isn't something you import through a menu. It's meant to be pasted straight into the editor:

  1. Open the GPO in the Group Policy Management Editor.
  2. Go to Computer Configuration or User Configuration → Preferences → Windows Settings → Registry.
  3. Open the generated .reg.xml in a text editor and copy the whole thing.
  4. Select the Registry node and paste (Ctrl+V).

The full tree shows up as registry preference items, collections and all. From there you can prune what you don't need or add item-level targeting.

Worth knowing

  • Large files don't blow up. The script streams the input and writes as it goes, so a multi-hundred-MB export stays well within memory. It isn't instant on something that big, but it gets there.
  • Broken keys are skipped, not fatal. Real registries (HKCU\Software\Classes is a repeat offender) sometimes hold keys or values with control characters that are illegal in XML. Left alone, a single one of those would corrupt the whole output. The script drops the affected key/value, logs the line number, and carries on.
  • Encoding is UTF-8 with an XML declaration, the same as what GPMC writes itself.
  • The changed timestamp is UTC, which is what the GPP format asks for.

Changelog

1.4.2

  • Output is now UTF-8 with an XML declaration (was UTF-16) to match what the GP editor produces
  • changed timestamp written in UTC, as the GPP spec requires
  • Keys or values with XML-illegal control characters are skipped instead of breaking the whole conversion
  • Fixed the changed attribute writing the month in place of the minutes
  • Fixed the trailing null terminator on REG_EXPAND_SZ / REG_MULTI_SZ being removed too greedily
  • Multi-line hex values no longer crash on a truncated file
  • A header without a subkey (e.g. [HKEY_LOCAL_MACHINE]) no longer throws
  • Reworked the key nesting (prefix comparison instead of Compare-Object): faster on big files and fixes a case where sibling keys could end up nested wrong

1.4.1

  • Fixed values that occasionally weren't written out
  • REG_BINARY no longer misread as REG_DWORD
  • Detects control characters in strings; added the uid and changed attributes and the BypassErrors option

1.4

  • Better escape-character handling, more hex types, and performance work for large files

Author

Jan Weis — it-explorations.de

Hit a .reg file it can't handle? Open an issue with a (sanitised) sample and I'll have a look.

About

🔄 Convert .reg files to GPP-compatible XML for easy deployment via Group Policy Preferences.

Topics

Resources

Stars

Watchers

Forks

Packages

Contributors