Last active
March 17, 2016 14:52
-
-
Save roubachof/16ff59ae55416c8803a4 to your computer and use it in GitHub Desktop.
Powershell function to add path to env path
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 AddTo-SystemPath { | |
Param([array]$PathToAdd) | |
$VerifiedPathsToAdd = $Null | |
Foreach($Path in $PathToAdd) { | |
if($env:Path -like "*$Path*") { | |
Write-Host "$Path already exists in Path statement" | |
} else { | |
$VerifiedPathsToAdd += ";$Path" | |
Write-Host "`$Path will be added to the environment path" | |
} | |
} | |
if($VerifiedPathsToAdd -ne $null) { | |
Write-Host "Adding $VerifiedPathsToAdd to Path statement now..." | |
[Environment]::SetEnvironmentVariable("Path",$env:Path + $VerifiedPathsToAdd,"Process") # replace 'Process' with [EnvironmentVariableTarget]::Machine, if you want to make this persistent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment