Skip to content

Instantly share code, notes, and snippets.

@baaamn
Created January 4, 2025 14:29
Show Gist options
  • Save baaamn/c8f43935841d6e9c4de2b3adc5734468 to your computer and use it in GitHub Desktop.
Save baaamn/c8f43935841d6e9c4de2b3adc5734468 to your computer and use it in GitHub Desktop.
# Powershell One-Liner that downloads the latest Python-Version for Windows and asks if it should install it right away. It even opens an elevated sessions with admin rights.
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$url = (Invoke-WebRequest -Uri 'https://www.python.org/downloads/windows/').Content | Select-String -Pattern 'https://www.python.org/ftp/python/\d+\.\d+\.\d+/python-\d+\.\d+\.\d+-amd64\.exe' -AllMatches | % { `$_.Matches[0].Value }; $path = `$env:USERPROFILE\Downloads\ + (`$url -split '/')[-1]; Invoke-WebRequest -Uri `$url -OutFile $path; if ((Read-Host 'Install? (Y/N)') -ieq 'y') { Start-Process -FilePath $path -Wait }`"" -Verb RunAs } else { $url = (Invoke-WebRequest -Uri 'https://www.python.org/downloads/windows/').Content | Select-String -Pattern 'https://www.python.org/ftp/python/\d+\.\d+\.\d+/python-\d+\.\d+\.\d+-amd64\.exe' -AllMatches | % { $_.Matches[0].Value }; $path = "$env:USERPROFILE\Downloads\" + ($url -split '/')[-1]; Invoke-WebRequest -Uri $url -OutFile $path; if ((Read-Host "Install? (Y/N)") -ieq 'y') { Start-Process -FilePath $path -Wait }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment