30 January 2008

Add Path Environment Variable in PowerShell

Adding a path to the PATH environment variable in the current PowerShell session is simpler than I thought:

> $env:path += ";path"

Note: remember to prepend the semi-colon to the new path make a valid path list.

You can make your PATH variable persistent using the SetEnvironmentVariable() .Net method:

[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";path", "target")

… where target is "Machine", "User" or "Process". Check the .Net documentation for what these values mean.

See also