简体   繁体   中英

PowerShell: Get 'tmp' environment variable raw value

$env:tmp

[Environment]::GetEnvironmentVariable('tmp', 'User')

(get-item hkcu:\Environment).GetValue('tmp')

All above PowerShell snippets return C:\\Users\\Roman\\AppData\\Local\\Temp value. I know that the value should be %USERPROFILE%\\AppData\\Local\\Temp (this I can see in regedit and in Environment Variables window).

I need to know 'original', but not 'resolved' value. How can I read this value in PowerShell?

Thanks.

Finally I have found a solution that works for me:

(get-item hkcu:\Environment).GetValue('tmp', $null, 'DoNotExpandEnvironmentNames')

I discovered this GetValue overload after writing following PowerShell/C# code:

$reg = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Environment", $true);
$val = $reg.GetValue('tmp', $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$val
$reg.Close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM