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.
Member_2_8171182Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
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.
0
Member_2_8171182Author Commented:
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.
0
footechCommented:
You could try something like the following:
$search = "sometext"
$regPath = "HKCU:\"
Get-ChildItem $regPath -Recurse | ForEach `
{
    $valueNames = $_.GetValueNames()
    foreach ($valueName in $valueNames)
    {
        If ( $valueName -match $search )
        { Remove-ItemProperty $_.PsPath -Name $valueName -WhatIf }
        ElseIf ( $_.GetValue($valueName) -match $search )
        { Remove-ItemProperty $_.PsPath -Name $valueName -WhatIf }
    }
}

Open in new window

You would need to remove the -WhatIf parameters to actually delete anything.  This should go without saying, but make sure you test before using, as there's potential to really screw things up if you put in a wrong search string.  You can change the $regPath variable to limit where you're searching.

I would recommend looking at tools like Nirsoft's RegScanner or Registry-Finder (don't know the maker) for searches.  They may help to validate the above, and just using them (maybe in conjunction with regedit) might be enough for you, especially if you don't have a whole lot of values to delete.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Do You Have a Trusted Wireless Environment?

A Trusted Wireless Environment is a framework for building a complete Wi-Fi network that is fast, easy to manage, and secure.

Member_2_8171182Author Commented:
Many Thanks! A quick follow up question,
Can the
-ErrorAction SilentlyContinue
parameter be used?
0
footechCommented:
Simple answer is, "yes", but it's a pretty vague question.
Where would you put it and what are you hoping to achieve?
0
Member_2_8171182Author Commented:
Similar to the first script, to ignore all errors.
0
footechCommented:
Sure, it won't pose any problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.