Skip to content

Instantly share code, notes, and snippets.

@roubachof
Last active March 17, 2016 14:52
Show Gist options
  • Save roubachof/16ff59ae55416c8803a4 to your computer and use it in GitHub Desktop.
Save roubachof/16ff59ae55416c8803a4 to your computer and use it in GitHub Desktop.
Powershell function to add path to env path
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