Changing the environment variables for PowerShell, Setting Path environment variable

Sharing is caring!

To Set the PATH environment variable in powershell , We can use following command

$env:Path = “anypath”;

To modify the PATH environment variable temporarily
$env:Path = $env:Path + “;C:scripts”
$env:Path += “;C:scripts”

Note: Before messing with your path in this way, make sure that you save a copy of your existing path which can be saved by running following

$env:path >> a.out in a PowerShell prompt.

You can also modify user/system environment variables permanently (i.e. will be persistent across shell restarts) with the following
### Modify system environment variable ###
( "Path", $env:Path, [System.EnvironmentVariableTarget]::Machine )

### Modify user environment variable ###
( "INCLUDE", $env:INCLUDE, [System.EnvironmentVariableTarget]::User )


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.