Reputation: 43
you probably know, that you can see your windows environment variables in a gui looking like this:
Image:
How do only get the variables in the top box?
What I tried:
echo %path%
in powershell or cmd: it combines the entry for path of both boxes.
How can I prevent that and only see the contents of the top path variable?
Upvotes: 1
Views: 1424
Reputation: 3923
You can use the .NET method for both User and System ("Machine"
)
[Environment]::GetEnvironmentVariables("User")
Upvotes: 2
Reputation: 16086
So, there are several ways to get this info... cmd.exe / PowerShell.exe
# CMD
For /F "Skip=2Tokens=1-2*" %A In ('Reg Query HKCU\Environment /V PATH 2^>Nul') Do @Echo %A=%C
# Or this...
reg query HKCU\Environment /v PATH
# PowerShell
(Get-Item -Path HKCU:\Environment).GetValue('PATH', $null, 'DoNotExpandEnvironmentNames')
# Or this
(Get-ItemProperty HKCU:\Environment).PATH
# Or just the path from from what Scepticalist shows
([Environment]::GetEnvironmentVariables("User")).Path
Upvotes: 1