Skip to content

Instantly share code, notes, and snippets.

@a5ync
Last active April 19, 2016 23:50
Show Gist options
  • Save a5ync/c9b32504f2f55aba079d6f3b443d4942 to your computer and use it in GitHub Desktop.
Save a5ync/c9b32504f2f55aba079d6f3b443d4942 to your computer and use it in GitHub Desktop.
Adding a new path to environment variable Path (Machine or User space)
$newPath = "c:\scripts\"
Write-host Preparing environment
$currentPath = [Environment]::GetEnvironmentVariable("Path",[EnvironmentVariableTarget]::User) #or ::Machine
if ($currentPath -like '*'+$newPath+'*')
{
Write-host 'System environment "Path" already contains ' $newPath
}
else {
Write-host 'Adding ' $newPath ' to System "Path"'
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";"+$newPath, [EnvironmentVariableTarget]::User) #or ::Machine
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment