Add Get-userRegistryPath example script
This commit is contained in:
parent
fa5a1738b7
commit
41465392e8
16
windows/Get-UserRegistryPath.ps1
Normal file
16
windows/Get-UserRegistryPath.ps1
Normal 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'"
|
||||||
Loading…
x
Reference in New Issue
Block a user