So I've 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?
-
Changing the actual environment variables can be done by using the env: namespace / drive info. For example this code will update the path environment variable
$env:Path = "SomeRandomPath";
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 your profile to initiate the settings. On startup, powershell will run any .ps1 files it finds in the WindowsPowerShell directory under my documents. Typically you have a profile.ps1 file already there. The path on my computer is
c:\Users\JaredPar\Documents\WindowsPowerShell\profile.ps1
JasonMArcher : $profile is an automatic variable that points at your user profile for all PowerShell hosts.Richard : Note that (split-path $profile)(to get the containing folder) can contain multiple profile files: profile.ps1 should be loaded by all hosts,_profile.ps1 just by the specified host. For PowerShell.exe (console host), this is Microsoft.PowerShell_profile.ps1. -
If you need to modify PATH environment variable temporarily, some time during PowerShell session, you can do it this way:
$env:Path = $env:Path + ";C:\Program Files\GnuWin32\bin"
-
you can also modify user/system environment variable like followings.
### Modify system environment variable ### [Environment]::SetEnvironmentVariable( "Path", $env:Path, [System.EnvironmentVariableTarget]::Machine ) ### Modify user environment variable ### [Environment]::SetEnvironmentVariable( "INCLUDE", $env:INCLUDE, [System.EnvironmentVariableTarget]::User )
0 comments:
Post a Comment