Details of the scenario you tried and the problem that is occurring
Trying to remove a registry value. I had been successfully creating Registry resources specifying the Keys in the "HKEY_LOCAL_MACHINE\*" format. However, when I switched to Ensure = 'Absent', it failed.
Verbose logs showing the problem
PowerShell DSC resource MSFT_RegistryResource failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find path 'C:\Windows\system32\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run' because it does not exist. + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : localhost
Suggested solution to the issue
Account for specifying keys in the HKEY_LOCAL_MACHINE format (which works for 'Present') in the code at:
|
if (-not [System.String]::IsNullOrEmpty($ValueName)) |
|
{ |
|
# If the user specified a registry key value with a name to remove, remove the registry key value with the specified name |
|
$null = Remove-ItemProperty -Path $Key -Name $ValueName -Force |
|
} |
The DSC configuration that is used to reproduce the issue (as detailed as possible)
Registry RemoveTeamsMachineAutoStart
{
Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run'
ValueName = 'Teams'
ValueType = 'String'
ValueData = '"C:\Program Files (x86)\Microsoft\Teams\current\Teams.exe"'
Ensure = 'Absent'
Force = $true
}
The operating system the target node is running
OsName : Microsoft Windows 10 Enterprise for Virtual Desktops
OsOperatingSystemSKU : 175
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage : en-US
OsMuiLanguages : {en-US}
Version and build of PowerShell the target node is running
Name Value
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Version of the DSC module that was used ('dev' if using current dev branch)
2.12.0.0
Details of the scenario you tried and the problem that is occurring
Trying to remove a registry value. I had been successfully creating Registry resources specifying the Keys in the "HKEY_LOCAL_MACHINE\*" format. However, when I switched to Ensure = 'Absent', it failed.
Verbose logs showing the problem
PowerShell DSC resource MSFT_RegistryResource failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find path 'C:\Windows\system32\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run' because it does not exist. + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : localhost
Suggested solution to the issue
Account for specifying keys in the HKEY_LOCAL_MACHINE format (which works for 'Present') in the code at:
PSDscResources/DscResources/MSFT_RegistryResource/MSFT_RegistryResource.psm1
Lines 309 to 313 in 7064eda
The DSC configuration that is used to reproduce the issue (as detailed as possible)
Registry RemoveTeamsMachineAutoStart { Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run' ValueName = 'Teams' ValueType = 'String' ValueData = '"C:\Program Files (x86)\Microsoft\Teams\current\Teams.exe"' Ensure = 'Absent' Force = $true }The operating system the target node is running
OsName : Microsoft Windows 10 Enterprise for Virtual Desktops
OsOperatingSystemSKU : 175
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage : en-US
OsMuiLanguages : {en-US}
Version and build of PowerShell the target node is running
Name Value
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Version of the DSC module that was used ('dev' if using current dev branch)
2.12.0.0