Search and delete registry entries using wildcards

Is it possible to search for a wildcard - an example *WAAgent*or to *WAHost*delete each registry key that refers to this template output above?

+5
source share
4 answers

You can try something like:

Get-ChildItem -Path HKLM:\ -Recurse -Include *WAAgent* -ErrorAction SilentlyContinue | Remove-Item
Get-ChildItem -Path HKLM:\ -Recurse -Include *WAHost* -ErrorAction SilentlyContinue | Remove-Item

You must specify in -Pathif they are located in HKLM (local computer) or HKCU (current user), since they are two different disks. This should be run as administrator and will give a lot of errors (so I used -ErrorAction SilentlyContinueto hide them).

: , , -, , . , , , foreach . , DARGEROUS .

+7

( ), - :

gci HKLM: -rec -ea SilentlyContinue | % { if((get-itemproperty -Path $_.PsPath) 
    -match "WAAGent") { $_.PsPath} } | Remove-Item  

@Graimer, !!!

+3

, ! . , , . WhatIf, .

Get-ChildItem Microsoft.PowerShell.Core\Registry:: -Include *WAAgent*,*WAHost* -Recurse |
Remove-Item -Recurse -Force -WhatIf
+2

I am having a problem with the session id on the registry path. To solve this problem, you got the first part of the registry, saved it in a variable, and used it for my foreach loop, where the keys for disk mappings were saved.

In my case, it was too strict.

The following is an example of deleting (local) disk mapping in a session (I had a problem).

Start-Sleep -Seconds 20

# This stores the Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\<SESSIONID>"
$SessionInfo = Get-Item "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\*"

cd "HKCU:\"

Start-Sleep -Seconds 1

$Items = Get-ChildItem "$SessionInfo\MyComputer\Namespace"

foreach($Item in $Items){

        Remove-Item $Item -Force -Recurse -Verbose

}
0
source

All Articles