5

I know I can ensure the presens of a specific registry value by using the following scriptblock:

    Registry ConfigureRegistry
    {
        Ensure    = 'Present'
        Key       = 'HKEY_LOCAL_MACHINE\SOFTWARE\SomeKey'
        ValueName = 'MachineType'
        ValueData = 'Hyper-V'
    }

But how can I delete the registry key SomeKey? If I only change the keyword Ensure = "Present" to Ensure = "Absent" it will leave the key SomeKey...

VertigoRay
  • 272
  • 1
  • 3
  • 9
Matthias Güntert
  • 2,438
  • 12
  • 39
  • 59

2 Answers2

3

This is now possible, see VertigoRay's answer.

This isn't possible at the moment with the Registry resource, as you've discovered.

You can use a Script resource or write a full custom resource instead.

briantist
  • 2,545
  • 1
  • 19
  • 34
3

This is possible, as documented:

To add or remove a registry key, specify [ValueName] as an empty string without specifying ValueType or ValueData.

Example

Registry ConfigureRegistry
{
    Ensure    = 'Absent'
    Key       = 'HKEY_LOCAL_MACHINE\SOFTWARE\SomeKey'
    ValueName = ''
}

PSDrives also work:

Registry ConfigureRegistry
{
    Ensure    = 'Absent'
    Key       = 'HKLM:\SOFTWARE\SomeKey'
    ValueName = ''
}
VertigoRay
  • 272
  • 1
  • 3
  • 9