KowalskiTom
KowalskiTom

Reputation: 187

How can I view all machine level environment variables using a single PowerShell command?

I can use this to get all of the user environment variables:

Get-ChildItem -Path Env:\

and this to get a single environment variable:

[System.Environment]::GetEnvironmentVariable('PATH','machine')

but what command can I use to view all machine level environment variables?

Upvotes: 4

Views: 2942

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

The System.Environment class has another static method GetEnvironmentVariables() (note the trailing "s"). You can call it without argument to get all environment variables (similar to Get-ChildItem env:), or with the same arguments as the second parameter of the GetEnvironmentVariable() method to get the variables for a particular target (e.g. machine, user, or process).

This will do what you want:

[Environment]::GetEnvironmentVariables('machine')

Upvotes: 7

Related Questions