Programmatically open RegEdit to a specific registry path

Here’s a quick PowerShell script to open RegEdit navigated to a specific path in the registry.  This can be handy as sometimes you are given a path but would like to explore/view/modify it in the RegEdit GUI.

We take advantage of the LastKey value to specify the location RegEdit should navigate to when opened, and then start a new instance of RegEdit using the -m switch to bypass the default single-instance behavior.  Without the -m switch, a currently-opened RegEdit will be focused, and the navigation will not occur.

$Replacements = @{':'='' # Remove PowerShell syntax
$Replacements.Keys | % {
    $key = $key.ToUpperInvariant().Replace($_, $Replacements[$_])
Write-Verbose "Open $Key"
sp HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\ -Name LastKey -Value $Key -Force
regedit -m # Open new instance

Paste the above into Open-RegEdit.ps1.  Use it as such:

PS> .\Open-RegEdit.ps1 hkcu:\Software\ODBC -Verbose

And RegEdit will open at the desired location.

May 25, 2013