How To Set Environment Variable Using PowerShell?

Environment Variables are used to store simple information at the operating system level which can be consumed by operating system services, applications, etc. for information sharing. PowerShell provides the ability to list and set environment variables via the PowerShell command line interface. We can use PowerShell to set environment variables like path, AppData, os, etc.

List Environment Variables

The Get-ChildItem command can be used to list current environment variables via PowerShell. We should provide the Env: as parameter to the Get-ChildItem command.

PS> Get-ChildItem Env:
List Environment Variables

The environment variables are stored inside the variable named $env . We can get a specific environment variable value by adding the variable name. In the following example, we display the HOMEPATH environment variable using the $env variable.


Set Environment Variable

We can set an environment variable value by using the PowerShell $env variable. We just add the environment variable name to the $env. In the following example, we set the environment variable named Programs.

PS> $env:Programs="Winamp"
See also  How To Change Environment Variables In Windows 10?

Leave a Comment