0

I am trying to get this script to find all registries containing "e:\UC" in either its data or name. Most of the matches are not going to be an exact match and "e:\UC" will be in the beginning or middle of the Data or Name.

This is the script I cannot get to work with what I am trying to do. I believe that it is checking the data but not the name.

$RE = 'e:\UC'
$Key = 'HKLM'
Get-ChildItem $Key -Rec -EA SilentlyContinue | ForEach-Object {
    $CurrentKey = (Get-ItemProperty -Path $_.PSPath)
    if ($CurrentKey -match $RE) {
        $CurrentKey | Remove-Item -Force -Whatif
    }
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 1
    [1] you are using a `\` in your regex pattern. i don't see where you are escaping that slash ... [*grin*] [2] have you tried any of the ideas in the following post? use PowerShell to search for string in registry keys and values - Stack Overflow — https://stackoverflow.com/questions/42963661/use-powershell-to-search-for-string-in-registry-keys-and-values – Lee_Dailey Apr 21 '19 at 23:45
  • See [here](https://stackoverflow.com/questions/17837876/how-to-filter-name-value-pairs-under-a-registry-key-by-name-and-value-in-powersh/46036422#46036422) about registry values enumeration – montonero Apr 22 '19 at 09:32
  • `'e:\UC'` -> `'e:\\UC'`, `'HKLM'` -> `'HKLM:'` – Ansgar Wiechers Apr 22 '19 at 11:42
  • Would i correct 'e:\UC' to have 2 "\\" even though it appears in the data with only one? – DerkaHasGame Apr 22 '19 at 19:26
  • As Lee_Daily already pointed out you MUST escape backslashes in a regular expression if you want them to match a literal backslash, otherwise they'll escape the subsequent character. Please read up on how regular expressions work. – Ansgar Wiechers Apr 23 '19 at 07:50

0 Answers0