PowerShell: get the value of the variable "tmp" environment variable

$env:tmp

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

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

All PowerShell snippets described above return a value C:\Users\Roman\AppData\Local\Temp. I know what the value should be %USERPROFILE%\AppData\Local\Temp(this can be seen in regedit and in the environment variables window).

I need to know the "original", but not the "permitted" value. How can I read this value in PowerShell?

Thank.

+3
source share
1 answer

Finally, I found a solution that works for me:

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

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

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

Source: https://habr.com/ru/post/1783496/


All Articles