Last active
August 29, 2015 14:01
-
-
Save rchaganti/047435aa1b1094188396 to your computer and use it in GitHub Desktop.
Download latest Python MSI from python.org/downloads
This file contains hidden or 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
Function Test-Url { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true)] | |
[String] $Url, | |
[Parameter()] | |
[Switch] $ReturnUri | |
) | |
Process { | |
if ([system.uri]::IsWellFormedUriString($Url,[System.UriKind]::Absolute)) { | |
$true | |
} else { | |
$false | |
} | |
} | |
} | |
Function Get-PythonMSI { | |
[CmdletBinding()] | |
param ( | |
[Parameter(ParameterSetName='Download')] | |
[Switch]$DownloadLatest, | |
[Parameter(ParameterSetName='Download',Mandatory=$false)] | |
[String]$DownloadPath = "$env:USERPROFILE\Downloads" | |
) | |
Process { | |
$Msi = @() | |
$doc = Invoke-WebRequest -Uri 'https://www.python.org/downloads' | |
foreach ($href in ($doc.links.href -ne '')) { | |
if ((Test-Url -Url $href) -and $href.EndsWith('.msi')) { | |
$uri = [System.uri]$href | |
$Msi += New-Object -TypeName PSObject -Property @{ | |
"Url" = $href | |
"Version" = $Uri.Segments[-2].Replace('/','') | |
} | |
} | |
} | |
if ($DownloadLatest) { | |
$MsiToInstall = $msi | Sort -Property Version -Descending | Select -First 1 | |
Start-BitsTransfer -Source $MsiToInstall.Url -Destination $DownloadPath | |
} else { | |
$Msi | |
} | |
} | |
} | |
#Usage | |
#get a list of all MSIs | |
Get-PythonMSI | |
#Download the latest MSI | |
Get-PythonMSI -DownloadLatest | |
#Download the latest MSI to a specific destination | |
Get-PythonMSI -DownloadLatest -DownloadPath C:\Downloads |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment