Created
July 30, 2022 22:00
-
-
Save ion1/4a28219089002cad018feea760d6213b to your computer and use it in GitHub Desktop.
Registry search and replace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Search = "E:\Music Production\" | |
$Replace = "D:\Music Production\" | |
function Confirm { | |
for (;;) { | |
Write-Host "[YNQ] " -NoNewline | |
$Key = [System.Console]::ReadKey().Key | |
Write-Host "" | |
switch ($Key) { | |
"Y" { return $true } | |
"N" { return $false } | |
"Q" { exit } | |
} | |
Write-Host "Please press Y/N/Q" | |
} | |
} | |
Get-ChildItem HKLM: -Recurse -ErrorAction SilentlyContinue | Foreach-Object { | |
$Path = $_ | |
$Path.Property | ForEach-Object { | |
$Key = $_ | |
if ($Key -like "*$Search*") { | |
$NewKey = $Key.Replace($Search, $Replace) | |
Write-Output "", "$Path", " k- $Key", " k+ $NewKey" | |
if (Confirm) { | |
Write-Output "Renaming" | |
Rename-ItemProperty -Path Registry::$Path -Name $Key -NewName $NewKey | |
$Key = $NewKey | |
} | |
} | |
$Value = $Path.GetValue($Key) | |
if ($Value -like "*$Search*") { | |
$NewValue = $Value.Replace($Search, $Replace) | |
Write-Output "", "$Path\$_", " - $Value", " + $NewValue" | |
if (Confirm) { | |
Write-Output "Changing" | |
Set-ItemProperty -Path Registry::$Path -Name $Key -Value $NewValue | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment