Skip to content

Instantly share code, notes, and snippets.

@ColtonPhillips
Created April 28, 2013 21:20
Show Gist options
  • Save ColtonPhillips/5478459 to your computer and use it in GitHub Desktop.
Save ColtonPhillips/5478459 to your computer and use it in GitHub Desktop.
A top secret powershell script to add paths to the system environment variables, hopefully.
function AddSystemPaths([array] $PathsToAdd) {
$VerifiedPathsToAdd = ""
foreach ($Path in $PathsToAdd) {
if ($Env:Path -like "*$Path*") {
echo " Path to $Path already added"
}
else {
$VerifiedPathsToAdd += ";$Path";echo " Path to $Path needs to be added"
}
}
if ($VerifiedPathsToAdd -ne "") {
echo "Adding paths: $VerifiedPathsToAdd"
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + "$VerifiedPathsToAdd","Machine")
echo "Note: The new path does NOT take immediately in running processes. Only new processes will see new path."
}
}