Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Registry search and replace
$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