I'm trying to remove all values from a registry key. When dealing with the registry in PowerShell, I always pass LiteralPath, and it works fine everywhere except for Remove-ItemProperty.
This does not work as I expected:
Remove-ItemProperty -LiteralPath 'HKCU:Delete_all_values' -Name *
but the regular -Path works:
Remove-ItemProperty -Path 'HKCU:Delete_all_values' -Name *
Official docs are silent on this matter. Any suggestions on what I'm doing wrong?
What you're really looking for is
Clear-Item- it'll remove all values but leave the key and any subkeys intact:Why doesn't
-Name *work with-LiteralPath?Using
-LiteralPathcauses the*-ItemPropertyprovider cmdlets to suppress all wildcard expansion - including for property names:You will observe the same behavior if you pipe a registry item, as PowerShell will bind the key's full provider path to
-LiteralPathby default:Explicitly passing the value names to
-Namewill solve the problem:At which point you might as well just use
Clear-Item