Created
April 28, 2013 21:20
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://blogs.technet.com/b/sqlthoughts/archive/2008/12/12/powershell-function-to-add-system-path.aspx
http://www.mikepfeiffer.net/2010/06/how-to-add-functions-to-your-powershell-session/