Skip to main content
case sensitive on unix!
Source Link
Sridhar Ratnakumar
  • 86.4k
  • 66
  • 151
  • 193

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:PathPATH = "SomeRandomPath";             (replaces existing path) 
$env:PathPATH += ";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

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

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
Note that most voted answer does not answered how to make the transformation permanent. So I emphatize the solution.
Source Link
Flavio Vilante
  • 6.1k
  • 1
  • 14
  • 15

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.

It's a script that automatic runs everytimeEverytime a new instance of Powershell starts, it look for specific script files (named profile files) and execute them if they do exist. You can use itedit one of these profile to customize your enviroment.

To know where the Powershellthose profile script isscripts are located in your computer type $profile. The path on my computer is:

C:\Users\JaredPar\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
$profile                                     
$profile.AllUsersAllHosts           
$profile.AllUsersCurrentHost        
$profile.CurrentUserAllHosts    
$profile.CurrentUserCurrentHost     

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

notepad $profile

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.

It's a script that automatic runs everytime a new instance of Powershell starts. You can use it to customize your enviroment.

To know where the Powershell profile script is located in your computer type $profile. The path on my computer is:

C:\Users\JaredPar\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

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
Formating. Note that most voted answer does not answered how to make the transformation permanent.
Source Link
Flavio Vilante
  • 6.1k
  • 1
  • 14
  • 15

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 your Powershell profilePowershell profiles script.

It's a script that automatic runs everytime a new instance of Powershell starts. You can use it to customize your enviroment.

To know where the Powershell profile script is located in your computer type $profile. The path on my computer is:

C:\Users\JaredPar\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

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)

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 Powershell profile script.

It's a script that automatic runs everytime a new instance of Powershell starts. You can use it to customize your enviroment.

To know where the Powershell profile script is located in your computer type $profile. The path on my computer is:

C:\Users\JaredPar\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

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.

It's a script that automatic runs everytime a new instance of Powershell starts. You can use it to customize your enviroment.

To know where the Powershell profile script is located in your computer type $profile. The path on my computer is:

C:\Users\JaredPar\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
make it more agnostic in relation to operational system (works in powershell 5, 6 and 7)
Source Link
Flavio Vilante
  • 6.1k
  • 1
  • 14
  • 15
Loading
Tried to make more clear that "WindowsPowerShell" is literal (though it is not entirely clear what "My Documents" refers to).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
added previously noted advice about preserving path
Source Link
Jon Schneider
  • 27.2k
  • 25
  • 158
  • 183
Loading
added previously noted advise about preserving path
Source Link
Loading
Active reading. [ <http://en.wikipedia.org/wiki/Windows_PowerShell>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
deleted 37 characters in body
Source Link
Zombo
  • 1
  • 69
  • 414
  • 436
Loading
added 25 characters in body
Source Link
Zombo
  • 1
  • 69
  • 414
  • 436
Loading
We have to go through the `"[Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")"` to make it permanent.
Source Link
user447356
user447356
Loading
Source Link
JaredPar
  • 759k
  • 151
  • 1.3k
  • 1.5k
Loading