I am trying to delete a binary value within my registry with this code the code prompts an error stating the value at DefaultConnectionSettings does exist but it's able to find the SID path, but not the exact DefaultConnectionSettings Value. I'm running this script on a test machine that has the DefaultConnectionSettings. RegEdit.exe screenshot
Any input would be helpful Thanks,
if (!(Test-Path 'HKU:\')) {
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
}
($path = Get-ChildItem -Path 'HKU:\*\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections' -ErrorAction SilentlyContinue) |
ForEach-Object { Remove-ItemProperty -Path $path -name "DefaultConnectionSettings" -force }
The registry value you're trying to delete is a value of the
registry::HKEY_USERS\*\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connectionsregistry keys themselves.HKEY_USERShive simply by prepending the provider prefixregistry::to the native registry path - no need to map a new drive withNew-PSDrivefirst.By contrast,
Get-ChildItemlooks for subkeys of the targeted keys.Thus, the immediate fix is to switch from
Get-ChildItemtoGet-Item, which returns objects representing the target keys themselves.However, you can do it all with a single
Remove-ItemPropertycall (as with your own attempt, running from an elevated session is assumed):Note: The
-WhatIfcommon parameter in the command above previews the operation. Remove-WhatIfonce you're sure the operation will do what you want.