Link to home
Start Free TrialLog in
Avatar of DUX_NEKRON
DUX_NEKRONFlag for Brazil

asked on

How i search all values and/or registry keys of a term with powershell to do mass deletion ou replacement?

How i search a term, like "nvidia" inside registry with powershell to delete or replace all related values and keys with another one like "nvidia2"?
.
.
Thanks Experts.
Avatar of soostibi
soostibi
Flag of Hungary image

This is my prototype. If you like it, I can make a function form it, so that it's easier to use.

You can set the $search and $root to test it.
$search = "arial"
$root = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'

Get-childItem $root -Recurse -ErrorAction silentlycontinue | %{
    if($_.name -match $search){
        New-Object -TypeName PSObject -Property @{
                    Path = $_.name
                    Name = $null
                    Value = $null
                    Type = $null
                }
            }
    else{
        $key = $_
        $key.getvaluenames() | %{
            if($_ -match $search){New-Object -TypeName PSObject -Property @{
                    Path = $key.name
                    Name = $_
                    Value = $key.getvalue($_)
                    Type = $key.getvaluekind($_)
                }
            }
        }
    }
} | Select-Object path,name, value, type

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of soostibi
soostibi
Flag of Hungary 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
Avatar of DUX_NEKRON

ASKER

Wonderful soostibi!!!

How can i save and call the SearchRegistry function ?

Thank you
SOLUTION
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
It didint worked.

Let's describe my steps:

(enable custom scripts)
1 - PS E:\> set-executionpolicy unrestricted

(the complete script solution)
2 - PS E:\> .\11scr.ps1

(for test)
3 - PS E:\> SearchRegistry -search Microsoft -root HKCU:\Software -recurse $false | Format-Table

Bad result, the log:

PS E:\> get-help set-executionpolicy
PS E:\> set-executionpolicy unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies
help topic. Do you want to change the execution policy?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
PS E:\> .\11scr.ps1
PS E:\> SearchRegistry -search Microsoft -root HKCU:\Software -recurse $false | Format-Table
The term 'SearchRegistry' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the p
ath is correct and try again.
At line:1 char:15
+ SearchRegistry <<<<  -search Microsoft -root HKCU:\Software -recurse $false | Format-Table
    + CategoryInfo          : ObjectNotFound: (SearchRegistry:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS E:\>

Open in new window

SOLUTION
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
Thank you soostibi, wonderful script and explanation, it worked like a charm, and Alok-Agarwal too to how proceed with powershell scripts
Cheers
DUX_NEKRON