Skip to content

Instantly share code, notes, and snippets.

@jdevera
Created June 29, 2019 12:17
Show Gist options
  • Save jdevera/d543695f074f879a62827a3e49975109 to your computer and use it in GitHub Desktop.
Save jdevera/d543695f074f879a62827a3e49975109 to your computer and use it in GitHub Desktop.
Make sure Python 2 is before Python 3 in the Windows PATH
$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