Author Posts

June 24, 2015 at 10:23 pm

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"' 

June 29, 2015 at 6:18 am

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.

July 6, 2015 at 4:22 pm

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.

July 6, 2015 at 9:20 pm

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.

July 11, 2015 at 2:01 am

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.

September 24, 2015 at 11:47 am

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

March 23, 2016 at 8:15 pm

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