2

How can I display environment variables in PowerShell, and be able to distinguish between which ones are "user" vars and which ones are "system" vars?

3 Answers 3

3

Not a powershell pro, but at worst, you could go fish around in the registry to see whether the vars you're interested in are showing up there. Inside a given session, I'm not really sure there's any distinction between user/sys vars other than the registry storage location...

Pertinent keys are:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
HKEY_CURRENT_USER\Environment
1
  • 2
    Correct: in process there is no distinction. And of course PATH is a combination of system and user settings so as set is neither.
    – Richard
    Apr 6, 2011 at 8:06
0

To find out within PowerShell:

Get-ItemProperty -Path 'Registry::HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'

Get-ItemProperty -Path 'Registry::HKCU\Environment'
0

Since PowerShell has access to the .NET Framework, you could use

[System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::Machine) [System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::Process) [System.Environment]::GetEnvironmentVariables([System.EnvironmentVariableTarget]::User)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .