Kristen Rw Johnson
Kristen Rw Johnson

Reputation: 327

Find values in registry subkeys and delete them

I'm trying to write a simple script in PowerShell (trying to keep it to one line) that will:

This is my code so far:

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

Beneath "KeyToQuery" is several subkeys of random names that contain identical values.

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

Where am I going wrong?

Upvotes: 4

Views: 22345

Answers (1)

CB.
CB.

Reputation: 60918

Try this:

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

Upvotes: 7

Related Questions