PowerShell – Return Environment Variables

email me

I was looking around for environmental variables in PowerShell, and it got me thinking….remember using the Set command at the Windows command line?

When you run the command, it displays the current environment variable settings.

Something like this:

C:\Users\Demo99>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Demo99\AppData\Roaming
asl.log=Destination=file
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=WORK
ComSpec=C:\WINDOWS\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
HOMEDRIVE=C:
HOMEPATH=\Users\Demo99
LOCALAPPDATA=C:\Users\Demo99\AppData\Local
LOGONSERVER=\\WORK
NUMBER_OF_PROCESSORS=4
OneDrive=C:\Users\Demo99\OneDrive
OneDriveConsumer=C:\Users\Demo99\OneDrive
OS=Windows_NT

 

So, what is the PowerShell equivalent?

Try this:

PS C:\WINDOWS\system32> [System.Environment]::GetEnvironmentVariables()

Name Value
—- —–
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
ProgramW6432 C:\Program Files
NUMBER_OF_PROCESSORS 4
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
PROCESSOR_IDENTIFIER Intel64 Family 6 Model 70 Stepping 1, GenuineIntel
asl.log Destination=file
PSModulePath C:\Users\Demo99\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modu…
USERDOMAIN WORK
PROCESSOR_REVISION 4601
HOMEPATH \Users\Demo99
OneDriveConsumer C:\Users\Demo99\OneDrive
USERNAME Demo99
USERPROFILE C:\Users\Demo99
USERDOMAIN_ROAMINGPROFILE WORK
windir C:\WINDOWS
COMPUTERNAME WORK
PUBLIC C:\Users\Public
Path C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Anaco…
LOCALAPPDATA C:\Users\Demo99\AppData\Local

 

Notes

dir env:

ls env:\

 

tags: PowerShell Environment, PowerShell Variables, MrNetTek