Filter and delete registry values ​​using Where-Object

I'm not sure why I find it so difficult. From under a specific registry key, I would like to request specific registry values ​​based on their data (rather than name) and delete the resulting registry values.

For instance:

screenshot of registry

How to remove any values ​​in this key that contain, say, "foo". I can list the registry values ​​with Get-ItemProperty 'HKCU:\Software\Policies\Google\Chrome\RestoreOnStartupURLs', but it mixes some junk along with the actual data:

1            : http://foo.example.com
2            : http://bar.example.com
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Policies\Google\Chrome\RestoreOnStartupURLs
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Policies\Google\Chrome
PSChildName  : RestoreOnStartupURLs
PSDrive      : HKCU
PSProvider   : Microsoft.PowerShell.Core\Registry

I tried to connect to Where-Objectbut cannot find a query that works. And then I need a cmdlet Remove-that can handle the result. Does anyone have any ideas?

+4
source share
1 answer

, . , , , - . , . , .

$KeyPath = 'HKCU:\Software\Policies\Google\Chrome\RestoreOnStartupURLs'
$ChromeKey = Get-Item $KeyPath

Microsoft.Win32.RegistryKey , . , , GetValueNames(), () , :

(default)
1
2

, Where, , Foo, . , , :

$ChromeKey.GetValueNames() | Where {$ChromeKey.GetValue($_) -match "foo"}

, 1. , , - Remove-ItemProperty...

$ChromeKey.GetValueNames() | Where {$ChromeKey.GetValue($_) -match "foo"} | ForEach{ Remove-ItemProperty -Path $KeyPath -Name $_ }

, , "foo" .

+6

All Articles