RegEdit remembers the last key you were in by writing it to the registry on close of RegEdit.
So if we set that registry key before opening RegEdit, it will be on the path we set.
To do this, we'll need the name of the current PowerShell path (Get-Location
), convert it to the format that Regedit saves it as (Convert-Path
with "Computer\"
prefixed to it), update the "LastKey" key/value in the registry (New-ItemProperty
), and then open RegEdit (Start-Process
).
Here's a small PowerShell script that will do that:
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit"
$name = "LastKey"
$value = "Computer\"+(Convert-Path (Get-Location))
New-ItemProperty -Path $regPath -Name $name -Value $value -PropertyType String -Force | Out-Null
Start-Process RegEdit