PowerShell: Display Environment Variables
List environment variables in PowerShell and learn why command output should be sanitized before being shared publicly.
A short PowerShell snippet to list all environment variables available in the current Windows session.
# Get all available environment variables
gci env:* | Sort-Object Name
# Shorter version
gci env:
gci is the built-in alias for Get-ChildItem. In PowerShell, the env: provider behaves like a small drive where environment variables are exposed as entries.
Example output:
Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\example.user\AppData\Roaming
CLIENTNAME WORKSTATION01
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
CommonProgramW6432 C:\Program Files\Common Files
COMPUTERNAME SERVER01
ComSpec C:\Windows\System32\cmd.exe
HOMEDRIVE C:
HOMEPATH \Users\example.user
LOCALAPPDATA C:\Users\example.user\AppData\Local
LOGONSERVER \DOMAIN-DC01
NUMBER_OF_PROCESSORS 8
OS Windows_NT
Path C:\Program Files\PowerShell\7;C:\Windows\System32;C:\Windows;...
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE AMD64
ProgramData C:\ProgramData
ProgramFiles C:\Program Files
ProgramFiles(x86) C:\Program Files (x86)
PSModulePath C:\Users\example.user\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;...
PUBLIC C:\Users\Public
SESSIONNAME Console
SystemDrive C:
SystemRoot C:\Windows
TEMP C:\Users\example.user\AppData\Local\Temp
TMP C:\Users\example.user\AppData\Local\Temp
USERDNSDOMAIN EXAMPLE.LOCAL
USERDOMAIN EXAMPLE
USERNAME example.user
USERPROFILE C:\Users\example.user
windir C:\Windows
Before publishing command output like this, review it carefully. Environment variable dumps often contain internal hostnames, domain names, usernames, paths, session identifiers, tool names, and sometimes access tokens or API keys. Replace those values with generic examples or shorten the output before sharing it publicly.