Created
June 29, 2019 12:17
-
-
Save jdevera/d543695f074f879a62827a3e49975109 to your computer and use it in GitHub Desktop.
Make sure Python 2 is before Python 3 in the Windows 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
$oldPath = (Get-ItemProperty -Path ` | |
'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' ` | |
-Name PATH).path | |
$pathParts = $oldPath.split(";") | |
$python = @() | |
$other = @() | |
foreach ($part in $pathParts) { | |
if ($part -like "*Python*") { | |
$python += ,$part | |
} | |
else | |
{ | |
$other += ,$part | |
} | |
} | |
$python = $python | sort | |
$all = $python + $other | |
$newPath = $all -join ";" | |
Set-ItemProperty -Path ` | |
'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' ` | |
-Name PATH ` | |
-Value $newPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment