Skip to content

Instantly share code, notes, and snippets.

@rido-min
Last active March 23, 2020 22:32
Show Gist options
  • Save rido-min/7f90cb8ecd15aaeee6a73f697ab30998 to your computer and use it in GitHub Desktop.
Save rido-min/7f90cb8ecd15aaeee6a73f697ab30998 to your computer and use it in GitHub Desktop.
AddTo-SystemPath.ps1
Function AddTo-SystemPath {
Param(
[array]$PathToAdd
)
$VerifiedPathsToAdd = $Null
Foreach($Path in $PathToAdd) {
if($env:Path -like "*$Path*") {
Write-Host "Currnet item in path is: $Path"
Write-Host "$Path already exists in Path statement" }
else { $VerifiedPathsToAdd += ";$Path"
Write-Host "`$VerifiedPathsToAdd updated to contain: $Path"}
if($VerifiedPathsToAdd -ne $null) {
Write-Host "`$VerifiedPathsToAdd contains: $verifiedPathsToAdd"
Write-Host "Adding $Path to Path statement now..."
[Environment]::SetEnvironmentVariable("Path",$env:Path + $VerifiedPathsToAdd,"Process")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment