PowerShell / PSDscResources

MIT License
129 stars 54 forks source link

Registry: Update only flag #174

Open MKletz opened 5 years ago

MKletz commented 5 years ago

I've come across the following situation a number of times and was wondering if there was any interest in getting this in as an optional flag. A boolean "Update" option on the resource that defaults to $False that will only update the key if it exists and not create it if its absent.

Example Situation: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MICROSOFT VISUAL STUDIO 2010 TOOLS FOR OFFICE RUNTIME (X64)" has the property "UninstallString" that is unquoted which for us is an audit finding. There is currently no way to tell the registry resource to set this to the desired value if the key exists without creating on systems with the run time absent.

Proposal: Optional parameter that tells the registry resource to only update the key if it exists. Meaning desired state is an absent key or an existing key matching the provided value.

Registry "Quote-UninstallString"
{
    Ensure = "Present"
    Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MICROSOFT VISUAL STUDIO 2010 TOOLS FOR OFFICE RUNTIME (X64)"
    ValueName = "UninstallString"
    ValueData = '"C:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\Microsoft Visual Studio 2010 Tools for Office Runtime (x64)\install.exe"'
    ValueType = "Dword"
    UpdateOnly = $True
}

if this would be accepted I would be happy to work on the PR