Add Get-userRegistryPath example script

This commit is contained in:
Corbin 2026-04-18 08:41:31 -04:00
parent fa5a1738b7
commit 41465392e8

View File

@ -0,0 +1,16 @@
$Username = ((Get-CimInstance win32_computersystem | ForEach-Object username) -split '\\')[1]
Write-Host "Signed in user is '$Username'"
# Map PSDrive for HKU
New-PSDrive -Name HKU -PSProvider Registry -Root hkey_users | Out-Null
# Find matching Volatile Env
try {
$Environment = ((Get-ItemProperty 'HKU:\*\Volatile Environment' | Where-Object Username -eq $Username).PSPath -split '\\')[2]
$UserRegistryPath = Join-Path -Path 'HKU:' -ChildPath $Environment
} catch [System.Security.SecurityException] {
Write-Error "Permission Denied"
throw System.Security.SecurityException
}
Write-Host "User registry path is '$UserRegistryPath'"