learn windows

How to Set Windows PowerShell Environment Variables

This tutorial guides you how to set Windows PowerShell environment variables. Are you facing problems where you had set PATH environment variables which works only for cmd command prompt and not from PowerShell ?

Set Windows PowerShell Environment Variables

PowerShell can access and manage environment variables. On windows environment variables are defined in three scopes as follows.

  1. System scope
  2. User scope
  3. Process scope

The Process scope contains the environment variables available in the current process, or PowerShell session. Whereas System scope contains the environment variables in Machine’s scope.

Note, when you change environment variables from PowerShell command prompt, the changes will affect only in the current session. This behavior is similar to > set path “%path%;<directory_path_you_want_to_set>”

You can check Path environment variable value from PowerShell using the following command

PS C:\Users\sneppets> $Env:Path

C:\Program Files\Java\openjdk-9.0.4\bin;.;C:\Program Files\apache-maven\bin;.;C:\Program Files\WSO2\EnterpriseIntegrato
r.4.0\bin;.;C:\Windows\System32;.;C:\Program Files\nodejs\;C:\Users\nithip\AppData\Roaming\npm

You can change Path environment variable value without using cmdlet using the following syntax

$Env:<variable-name> = "<new-value>"

For example, if you wanted to append “;E:\Work” to the value of the Path environment variable then you can use the following syntax

PS C:\Users\nithip> $Env:Path += ";E:\Work"

PS C:\Users\nithip> $Env:Path

C:\Program Files\Java\openjdk-9.0.4\bin;.;C:\Program Files\apache-maven\bin;.;C:\Program Files\WSO2\EnterpriseIntegrato
r.4.0\bin;.;C:\Windows\System32;.;C:\Program Files\nodejs\;C:\Users\nithip\AppData\Roaming\npm;E:\Work

Set/Change Path Environment Variable value using cmdlet

You can also use Item cmdlets such as Set-Item , Remove-Item , and Copy-Item  to set/change values of environment variables.

For example, to change Path environment variable using Set-Item cmdlet, to append “;c:\Temp” to the value of the Path, you need to use the following syntax.

PS C:\Users\nithip> Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")

PS C:\Users\nithip> $Env:Path

C:\Program Files\Java\openjdk-9.0.4\bin;.;C:\Program Files\apache-maven\bin;.;C:\Program Files\WSO2\EnterpriseIntegrato
r.4.0\bin;.;C:\Windows\System32;.;C:\Program Files\nodejs\;C:\Users\nithip\AppData\Roaming\npm;E:\Work;C:\Temp

Also See:

References:

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments