-
-
Save klevcsoo/f26e03aa491a48be27f6517014a17d01 to your computer and use it in GitHub Desktop.
Param( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[string] $RegistryPath, | |
[Parameter(Mandatory = $true, Position = 1)] | |
[string] $SearchQuery, | |
[Parameter(Mandatory = $true, Position = 2)] | |
[string] $NewValue | |
) | |
$Registry = Get-ChildItem $RegistryPath -Recurse | |
foreach ($a in $Registry) { | |
$a.Property | Where-Object { | |
$a.GetValue($_) -Like "*$SearchQuery*" | |
} | ForEach-Object { | |
$CurrentValue = $a.GetValue($_) | |
$ReplacedValue = $CurrentValue.Replace($SearchQuery, $NewValue) | |
Write-Output "Changing value of $a\$_ from '$CurrentValue' to '$ReplacedValue'" | |
Set-ItemProperty -Path Registry::$a -Name $_ -Value $ReplacedValue | |
} | |
} |
$RegistryPath = "-------"
$SearchQuery = "-----"
$NewValue = "-----"
)
$Registry = Get-ChildItem $RegistryPath -Recurse
foreach ($a in $Registry) {
$a.Property | Where-Object {
} | ForEach-Object {
$CurrentValue = $a.GetValue($)
$ReplacedValue = $CurrentValue.Replace($SearchQuery, $NewValue)
Write-Output "Changing value of $a$_ from '$CurrentValue' to '$ReplacedValue'"
Set-ItemProperty -Path Registry::$a -Name $_ -Value $ReplacedValue
}
}
Thanks for this !
Was searching to do a replace of values c:<Dir> to d:<Dir> in my registry and this example really helped !
I should only change line 17 to
$ReplacedValue = $CurrentValue.tolower().Replace($SearchQuery.ToLower(), $NewValue)
This will ignore the casing of the search
And responding to @FrightRisk
Save the file and run it like this :
.\replacereg.ps1 "HKCU:" "C:\Pinball" "D:\Pinball"
This replaces all my c:\pinball entries to d:\pinball
Again thanks for sharing
Hello. Do you have any instructions on how to use this? I want to search the entire registry for "mark" and replace it with "fred". Can you help?