Setting Windows PowerShell environment variables

I have found out that setting the PATH environment variable affects only the old command prompt. PowerShell seems to have different environment settings. How do I change the environment variables for PowerShell (v1)?

Note:

I want to make my changes permanent, so I don’t have to set it every time I run PowerShell. Does PowerShell have a profile file? Something like Bash profile on Unix?

2Best Answer
21

Changing the actual environment variables can be done by
using the env: namespace / drive information. For example, this
code will update the path environment variable:

$env:Path = "SomeRandomPath";             (replaces existing path) 
$env:Path += ";SomeRandomPath"            (appends to existing path)

Making change permanent

There are ways to make environment settings permanent, but
if you are only using them from PowerShell, it’s probably
a lot better to use Powershell profiles script.

Everytime a new instance of Powershell starts, it look for specific script files (named profile files) and execute them if they do exist. You can edit one of these profile to customize your enviroment.

To know where those profile scripts are located in your computer type:

$profile                                     
$profile.AllUsersAllHosts           
$profile.AllUsersCurrentHost        
$profile.CurrentUserAllHosts    
$profile.CurrentUserCurrentHost     

You can edit one of them, for example, by typing:

notepad $profile

Leave a Comment