PowerShell: Add a path to Path Environment Variable

By Xah Lee. Date: . Last updated: .

Add a Path to Environment Variable PATH

Add for current session

add to the end

$env:PATH = $env:PATH + ";" + "c:/Python39/"

add to the beginning

$env:PATH = "c:/Python39/" + ";" + $env:PATH

Add to registry

For current user

$newPath = "C:/Python39/";
$oldPaths = [environment]::GetEnvironmentVariable("path", "User");
[Environment]::SetEnvironmentVariable("path", $oldPaths + ";" + $newPath, "User")

restart PowerShell to see the new value.

For all users

$newPath = "C:/Python39/";
$oldPaths = [environment]::GetEnvironmentVariable("path", "Machine");
[Environment]::SetEnvironmentVariable("path", $oldPaths + ";" + $newPath, "Machine")

restart PowerShell to see the new value.

PowerShell. Environment Variable