DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Registry meta-resource

Open SteveL-MSFT opened this issue 2 years ago • 0 comments

Summary of the new feature / enhancement

There may be a large set of applications on Windows that store their configuration in the registry. It may make sense to have the registry resource accept a file that maps registry locations to a resource definition.

Proposed technical implementation details (optional)

For example, PS7 uses two registry values to control Microsoft Update:

HKLM\Software\Microsoft\PowerShellCore\UseMU = 1 HKLM\Software\Microsoft\PowerShellCore\InstalledVersions\39243d76-adaf-42b1-94fb-16ecf83237c8\Install = 1

The first enables updating via MU and the second installs if not installed (update doesn't do anything if not installed).

The registry resource could have parameters like registry -resourceFile ps7.json which contains:

{
  "name": "PowerShellMicrosoftUpdate",
  "version": "1.0.0",
  "properties": {
    "automaticUpdates": {
        "key": "HKLM\Software\Microsoft\PowerShellCore",
        "name": "UseMU",
        "valueType": "DWORD",
        "values": [ 0, 1 ]
    },
    "automaticInstall": {
        "key": "HKLM\Software\Microsoft\PowerShellCore\InstalledVersions\39243d76-adaf-42b1-94fb-16ecf83237c8",
        "name": "Install",
        "valueType": "DWORD",
        "values": [ 0, 1 ]
    }
  }
}

This is hypothetical and the values property needs to be thought out on how to properly support this. Also, for the registry resource to synthesize a DSC resource, it would need to generate JSON schema or implement the validate subcommand and perform its own validation against the incoming JSON (this seems more feasible).

Each synthetic resource would need it's own resource manifest that uses the registry resource. In this example, imagine a microsoft.powershell.microsoftupdate.dsc.json file in a location either the registry resource is aware of or in the same location as registry.exe:

{
  "manifestVersion": "1.0",
  "type": "Microsoft.PowerShell/MicrosoftUpdate",
  "version": "0.1.0",
  "get": {
    "executable": "registry",
    "args": [
      "get",
      "--resourceFile",
      "microsoft.powershell.microsoftupdate.json"
    ],
    "input": "stdin"
  },
  "set": {
    "executable": "registry",
    "args": [
      "set",
      "--resourceFile",
      "microsoft.powershell.microsoftupdate.json"
    ],
    "input": "stdin"
  },
  "test": {
    "executable": "registry",
    "args": [
      "test",
      "--resourceFile",
      "microsoft.powershell.microsoftupdate.json"
    ],
    "input": "stdin"
  },
  "validate": {
    "executable": "registry",
    "args": [
      "validate",
      "--resourceFile",
      "microsoft.powershell.microsoftupdate.json"
    ],
    "input": "stdin"
  },
  "exitCodes": {
    "0": "Success",
    "1": "Invalid parameter",
    "2": "Invalid input",
    "3": "Registry error",
    "4": "JSON serialization failed"
  }
}

SteveL-MSFT avatar Jul 14 '23 22:07 SteveL-MSFT