Link to home
Start Free TrialLog in
Avatar of Member_2_8171182
Member_2_8171182

asked on

PowerShell Delete Value From Registry With String In File-Name

I have A PowerShell Script that will delete Key with string in name.
I need help with A script that will delete Value with string in name

This will delete by string in folder name from registry.
# Folders (Key)
Get-ChildItem -Path HKLM:\ -Recurse -Include *String* -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -confirm:$false -Whatif

Open in new window


I have use this to delete string in file-name.
cd $env:SystemRoot
$string = "String"
get-childitem -recurse| where-object {$_.Name -like "*$string*"} | foreach ($_) {remove-item $_.fullname -recurse -confirm:$false}

Open in new window


Thanks in advanced.
Avatar of footech
footech
Flag of United States of America image

Let's throw out the terms folder and file when referring to the registry (unless we were talking about the actual files that the registry is based on).
We've got registry keys, which are shown in the left pane in regedit; and we've got registry values, which are shown in the right pane in regedit.  Registry values have a name, type, and data.

Are you asking to delete any registry value where its name matches (even partially) a particular string?

*Item cmdlets are used to work with with keys (though output formatting from the Get-Item and Get-ChildItem cmdlets shows some info about values as well, since PS 3.0+), while *-ItemProperty cmdlets are used with values.
Avatar of Member_2_8171182
Member_2_8171182

ASKER

Are you asking to delete any registry value where its name matches (even partially) a particular string?

Yes Actually, Values or Data. The first script will delete keys containing string from the registry. (Apologies for my ignorance.)

The second script is for file and directories containing string in file name.
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many Thanks! A quick follow up question,
Can the
-ErrorAction SilentlyContinue
parameter be used?
Simple answer is, "yes", but it's a pretty vague question.
Where would you put it and what are you hoping to achieve?
Similar to the first script, to ignore all errors.
Sure, it won't pose any problem.