Converting group policy registry preferences to PowerShell scripts

Most of the clients at my firm are moving to cloud only solutions in which we have less management options available. We can use Intune for Administrative Templates, or as we do use our RMM system as the management platform. To make sure we can use our RMM system we have several scripts that deploy registry keys in the same way as the GPO does. If you want to find what keys a GPO sets you can use this website.

Now the issue with this is that you do not directly have the option to deploy Group Policy Preferences instead of Group Policy Administrative Templates. A lot of our clients have these for applications that do not support ADMX files. To convert these I’ve created the following script.

The conversion script

 function convert-gpo($GPOFilePath) {
    $XMLFile = get-content $GPOFilePath
    $RegKeys = ($xmlfile | Select-Xml -Xpath "//Registry")
    foreach ($regkey in $RegKeys) {
        #Converting Hkey to actual path
        switch ($regkey.hive) {
            "HKEY_CURRENT_USER" { $regkey.hive = "HKCU:" ; break }
            "HKEY_LOCAL_MACHINE" { $regkey.hive = "HKLM:" ; break }
        $RegPath = Join-Path $regkey.hive $regkey.key
        write-host "####### $($RegPath) with $($ #######"
        write-host "New-ItemProperty -Path $($RegPath) -name $($ -Value $($regkey.value) -Force"
        write-host "####### NEXT KEY #######"

Using this script you can run the Convert-GPO function with the file path of the export of your GPO preference file as the only parameter.

The script will then write a new script using write-host. You can copy and paste this to your RMM system, or save it as a file by running "Convert-GPO $Filename | out-file NewScript.ps1" and that’s it! as always, Happy PowerShelling.


  1. ABeauchamp November 6, 2019 at 9:58 am

    nice work

    makes it easy to use w/ inTune

  2. LostintheWeeds February 8, 2021 at 6:26 pm

    Hello, this is exactly what I need and am looking for, however I must be being stupid and doing something wrong. Once I’ve run the script. I use convert-gpo “C:\GPPtoPS\settings.xml and receive a mass of red errors along the lines of.

    Select-Xml : Cannot convert value ” ” to type “System.Xml.XmlDocument”. Error: “Unexpected end tag. Line 1,
    position 5.”
    At line:3 char:28
    + $RegKeys = ($xmlfile | Select-Xml -Xpath “//Registry”).Node.prope …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Select-Xml], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidCastToXmlDocument,Microsoft.PowerShell.Commands.SelectXmlCommand

    Any help would be appreciated

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.