PowerShell:获取'tmp'环境变量原始值 [英] PowerShell: Get 'tmp' environment variable raw value

查看:446
本文介绍了PowerShell:获取'tmp'环境变量原始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$env:tmp

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

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

以上PowerShell代码片段返回 C:\Users\Roman\AppData\Local\Temp value。我知道该值应该是%USERPROFILE%\AppData\Local\Temp (这可以在regedit和环境变量窗口中看到)。

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).

我需要知道'原始',而不是'解决'的价值。如何在PowerShell中读取此值?

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

谢谢。

推荐答案

最后,我找到了一个适用于我的解决方案:

Finally I have found a solution that works for me:

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

写入以下PowerShell / C#后,我发现了GetValue重载代码:

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()

这篇关于PowerShell:获取'tmp'环境变量原始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆