$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开发者_JAVA技巧 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()
精彩评论