Find values ​​in registry subkeys and delete them

I am trying to write a simple script in PowerShell (trying to save it in one line) which will be:

  • List all subkeys in a registry key recursively
  • Find one that has a specific meaning
  • Delete another value for the section found in the previous step

This is my code:

Get-ChildItem "HKLM:\Software\Microsoft\KeyToQuery" -Recurse | Where-Object {$_.ValueA -eq "True"} 

Under "KeyToQuery" are several subsections of random names that contain the same value.

The first part of this work, but the Where-Object statement never evaluates to true. I also tried -match and-like to no avail.

Where am I going wrong?

+4
source share
1 answer

Try the following:

 Get-ChildItem "HKLM:\Software\Microsoft\KeyToQuery" -Recurse | ForEach-Object { Get-ItemProperty $_.pspath } | Where-Object {$_.ValueA -eq "True"} 
+7
source

Source: https://habr.com/ru/post/1447131/


All Articles