If sometime during a PowerShell session you need to see or to temporarily modify the PATH environment variable, you can type one of these commands:
Copy$env:Path # shows the actual content
$env:Path = 'C:\foo;' + $env:Path # attach to the beginning
$env:Path += ';C:\foo' # attach to the end
Answer from mloskot on Stack OverflowIf sometime during a PowerShell session you need to see or to temporarily modify the PATH environment variable, you can type one of these commands:
Copy$env:Path # shows the actual content
$env:Path = 'C:\foo;' + $env:Path # attach to the beginning
$env:Path += ';C:\foo' # attach to the end
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:
Copy$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:
Copy$profile
$profile.AllUsersAllHosts
$profile.AllUsersCurrentHost
$profile.CurrentUserAllHosts
$profile.CurrentUserCurrentHost
You can edit one of them, for example, by typing:
Copynotepad $profile
Set a persistent environment variable on a windows 10 computer with PowerShell?
Setting local variables in Powershell/CMD
Adding a path to environment variable
What is an environment variable and how is it used?
Videos
I need to set a system wide environment variable and I need it to be persistent.
Every time I try setting it with PowerShell it seems to only be good for that PowerShell session.
Is there a way to do this with PowerShell?