Unfortunately, when using the following PowerShell command, it erases all other entries in your PATH Environment Variable. Most forums I’ve seen are telling people to do this, good thing I backed up my paths before trying this method, as all my paths got erased.

[Environment]::SetEnvironmentVariable("PATH","C:\Testing","Machine")

Let’s see if we can fix this, first let us exam our current paths we have configured (it’s good to take a backup of this configuration before you make any changes, you can do that with the following PowerShell command:

$env:path | Out-File C:\EnvironmentVariableBackup.txt

Script:

Let’s create a whole script now so we can update the PATH Environment Variable and be able to use it in the future. I saved this to a file named UpdatePathEnvironmentVariable.ps1.

# Separate multiple paths with semi-colon ;
$NewPathsToAdd = "C:\Testing;C\Testing2"
# Save this to a text file in case you need it later, for now we'll output it to the console
$CurrentPaths = $env:path
Write-Host "`r`n `$CurrentPaths variable contains the following paths: $($currentPaths)" -ForegroundColor Cyan
# Combine the old path and new path(s) into one string, you can swap these variables around if you want the new paths at the bottom
$PathUpdate = $NewPathsToAdd + ";" + $CurrentPaths
Write-Host "`r`n `$PathUpdate variable will load the following paths: $($PathUpdate)" -ForegroundColor Cyan
# The last parameter ("Machine"),should be either User or Machine, depending on where you want the variable stored
[Environment]::SetEnvironmentVariable("PATH","$PathUpdate","Machine")