—Update – 01.03.20
A very friendly fellow by the name of Dennis Mutsaers was kind enough to review the script code a tweak it a little to remove an error in one of my below screenshots. Thanks Dennis – @dennismutsaers
—Update – 01.03.20
In some scenarios I’ve been passed a .reg file that needs to be applied to live running servers. I am a fan of deploying all settings possible using GPO’s and so I was in a position where I needed a solution (rather than site and manually type) to import a .reg file into Group Policy.
There is currently no easy solution in order to achieve this, you can use the Registry Wizard inside Group Policy Management but that’s only helpful if the registry files already exist and again still takes some time.
So… without further adieu the solution I found is explained below.
Group policy files are all XML based, as long as you can get your registry files into an XML format that Group Policy will understand then it will all work fine.
To do this, I used a script written by Malcolm McCaffery which allows you to export a .reg file from Regedit and then simply convert it to XML files to import.
Beware though, whatever you export you will need to split the different hives from the file – split your HKLM hive, HKCU hive and HK_CLASSES hive into separate registry files after export.
To achieve this:
Open Regedit, find the specific registry key you want to export and right client – Export.
Save this file to a location of your choosing, I have placed all the files into the same folder location, just in a folder on my desktop as an example.
Fire up a powershell prompt and browse to the directory where your files sit.
Now run the following command to convert your reg file to xml.
.\Reg2GPO.ps1 “<Path To Reg>” “<Path To XML>”
This envokes the powershell script. You will then be promoted for you paths to your .reg and .xml files.
Now you should have an xml file too.
Now simply right click your .xml file and select “copy”. Now open up your Group Policy Editor and in the registry section select paste.
Confirm your Import as prompted and you will see your registry entries imported
Give it a go and let me know your feedback.
File attached.
works as designed. thx for that
Awesome Script. Saved me about 4 hours of manually importing reg settings for some sh**ty app. Thanks 🙂
You’re welcome Tom
Script is gone (ps1) from other site… Do you have a copy?
Nevermind… Saw it at bottom… Doh!
I get an error as i don’t have a c:\support folder, line 415 in script calls the function again referencing this folder which doesnt exist, and a citrix reg file….
Convert-Reg2Xml -regPath “C:\support\ReceiverCSTRegUpx64.reg” -xmlPath C:\support\Citrix.xmlfunction Convert-RegEscapeCodes
Convert-Reg2Xml : A positional parameter cannot be found that accepts argument ‘Convert-RegEscapeCodes’.
Hi Roy, I’ll need to see the reg file you’re trying to convert. Can you send it over to me?
I get the same error, and I believe the same error is shown in your screenshot.
Drop me an email Dennis, send me your screenshot.
I kept getting an error saying the xml file is corrupt and will be ignored – turned out the GPO editor doesn’t like copying and pasting the xml file from a network drive!
Thanks for this 🙂
No worries Steve. Thanks.
Great script thx
Thank you!! Saved me a ton of work 🙂
You cannot call a method on a null-valued expression.
At D:\Scripts\Reg2GPO.ps1:40 char:5
+ $line = $sr.ReadLine()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Hmmm. Any ideas?
Looks like it has failed to read in your reg file.
I have the same problem.
You cannot call a method on a null-valued expression.
At C:\#temp\regkey\Reg2GPO.ps1:41 char:9
+ if ($line.StartsWith(“[“))
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\#temp\regkey\Reg2GPO.ps1:40 char:5
+ $line = $sr.ReadLine()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any ideas? What could be the problem?
Kind Regards, Pascal
Please email me the files you are trying to use and I’ll take a look at them.
I get the same error 🙁
Send me your files via email, I’ll take a look.
I got the same error, but found that it worked if I used the full path to the .reg and .xml files
.\Reg2GPO.ps1 C:\Users\petey247\Desktop\export.reg C:\Users\petey247\Desktop\export.xml
Thanks for the feedback Pete. I’ve requested examples a couple of times but no one sent them over. Definitely use the full path, the script launches addition processes and those wont be relative.
Hi there!
I can confirm I was getting this same error, and Petey247’s solution was a life saver. Thanks to him… AND TO LEEE JEFFRIES!
I love you. You saved my life.
Worked like a charm thanks for this. Helped me not have to click through a bunch in the registry wizard.