Listing environment variables with Powershell
A pretty basic Powershell command that everyone uses to list environment variables is:
ls env:
A few caveats here: this is NOT going to work in Linux or MacOS because in those environments the alias
ls
is not defined[^1]. Therefore the safest bet is to use
Get-ChildItem
instead.
Also, this is shown in table format (which is nice), but it truncates long values (which is not nice with variables like
PATH
):
In order to avoid that we can re-format the output in this way:
Get-ChildItem env: | Format-Table -Wrap
This will show a long value like this:
Finally, if you miss the classical format you get from Linux
env
or Windows CMD
set
, you can do the following:
Get-ChildItem env: | % { "$($_.Name)=$($_.Value)" }
It shows like this: