How to change default values in registry with DSC registry resource

This topic contains 6 replies, has 4 voices, and was last updated by  Zuldan 2 years, 2 months ago.

  • Author
  • #26804


    Hi all,

    I'm trying to change the default value for a key. When I try do this with the Registry Resource it simply creates a "second" (Default) value in key. Is it a bug or am I doing it wrong?

            Registry WinDirStatDirectoryConfig {
                DependsOn = "[Archive]InstallWinDirStat"
                Ensure = 'Present'
                Force = $True
                Key = 'HKEY_CLASSES_ROOT\Directory\shell\Show WinDirStat\command'
                ValueName = "(Default)"
                ValueType = 'String'
                ValueData = '"C:\Program Files (x86)\WinDirStat\windirstat.exe" "%1"' 
  • #26922

    Don Jones

    The "(Default)" isn't a discrete value – that is, it isn't an ItemProperty the way other values are. For example, in the shell, you'd do this to set a key's default value:

    Set-Item -Path HKCU:\Software\ScriptingGuys -Value "MyNewValue" -Type string

    You're just setting the value of the key itself – not creating a new ItemProperty. So you don't specify a ValueName.

    The problem is that the Registry resource mandates ValueName – which sort of suggests that it can't work with keys ("items") but only with values ("item properties"). If it can't directly modify a key, then there's no way to set the default value.

    You could probably work around this by using a Script resource, and using Get-Item and Set-Item in the Test{} and Set{} script blocks.

  • #27224


    Many thanks for the response Don.

    I think I'm going to make a custom resource as I need to make changes to user hives as well which the Registry resource does not support.

  • #27241

    Dave Wyatt

    The default value is actually an empty value name, but of course, MOF doesn't allow you to have empty strings assigned to Key properties.

    In a similar resource I wrote for modifying local GPO registry.pol files, I worked around this problem by combining the key / value names into a single Key property. If you wanted to modify the default value, you'd just specify a key path with a trailing backslash. This might be a good thing to log on Connect, or to add in the form of an xRegistry resource down the road.

  • #27417


    I have submitted a suggestion on Connect (

    I tried your workaround plus variations to it but could not get DSC to modify the default value. I wrote a Script resource to get around the problem.

    Thank you Dave and Don for your time.

  • #30061

    Chris Bowen

    Looks like this was fixed with the Powershell 5.0 release. If you set the ValueName="" it will now set the default value.

  • #36931


    @chris, thanks for the heads up. You are correct! It's now been fixed 😉

You must be logged in to reply to this topic.