DSC having trouble parsing registry key with a colon in it

Hi,

It seems that the registry DSC resource is having trouble when the registry key has the colon (":") and “{” “}” characters.
The error for the code below is:

PowerShell DSC resource MSFT_RegistryResource failed to execute Test-TargetResource functionality with error message: (ERROR) Invalid PSDrive
‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\SnapIns\FX’ specified in registry key
‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\SnapIns\FX:{4bbd4ebc-d808-4efc-b0a6-83c62e4ac931}’

Configuration secRMM-Removable-Media-Policy
{
    Import-DscResource -ModuleName ‘PSDesiredStateConfiguration’;
    Import-DscResource -Name Script;
    Node “localhost”
    {
        $registryKey = ‘{0}:{1}’ -f ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\SnapIns\FX’, 
        ‘{4bbd4ebc-d808-4efc-b0a6-83c62e4ac931}’;
        Registry secRMMIsInstalledOnNode
        {
            Ensure      = ‘Present’
            Key         = $registryKey
            ValueName   = ‘Description’
            ValueData   = ‘Security Removable Media Manager’
            ValueType   = ‘String’
        }
        Script secRMMScript
        {
            GetScript =
            {
                @{}
            }
            TestScript =
            {
                $false
            }
            SetScript =
            {
                Write-Verbose ‘Hello’
            }
            DependsOn = ‘[registry]secRMMIsInstalledOnNode’;
        }
    }
}

Looks like a bug in Registry DSC provider. It tries to convert HKEY_LOCAL_MACHINE to HKLM: and the logic is based on ‘:’, since it already has ‘:’ in the path it skips that conversion.

You can use HKLM: instead if HKEY_LOCAL_MACHINE to solve the problem.

@gaelcolas, correct me if I’m wrong.

Hi,

Thanks for the quick response.
Unfortunately, your suggestion did not fix the issue.
For now, I am using a simpler registry key.
Thanks again sir!

Hi,

I wanted to let you know that your suggestion DID work.
I forgot the : in front of HKLM.
Sorry about that and thanks!

Good to hear :-). I will close this thread.