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.
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_SZREG_EXPAND_SZREG_MULTI_SZREG_BINARYREG_DWORDREG_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.
- PowerShell 3.0 or newer (every supported Windows already has this)
- A
.regfile in the normalregeditexport format (the one starting withWindows Registry Editor Version 5.00)
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 ReplaceThe output isn't something you import through a menu. It's meant to be pasted straight into the editor:
- Open the GPO in the Group Policy Management Editor.
- Go to Computer Configuration or User Configuration → Preferences → Windows Settings → Registry.
- Open the generated
.reg.xmlin a text editor and copy the whole thing. - 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.
- 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\Classesis 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
changedtimestamp is UTC, which is what the GPP format asks for.
- Output is now UTF-8 with an XML declaration (was UTF-16) to match what the GP editor produces
changedtimestamp 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
changedattribute writing the month in place of the minutes - Fixed the trailing null terminator on
REG_EXPAND_SZ/REG_MULTI_SZbeing 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
- Fixed values that occasionally weren't written out
REG_BINARYno longer misread asREG_DWORD- Detects control characters in strings; added the
uidandchangedattributes and theBypassErrorsoption
- Better escape-character handling, more hex types, and performance work for large files
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.
