Skip to content

Using Powershell To Retrieve Latest Package Url From Github Releases#

Github can host package releases, I will show you how to use Powershell to retrieve the latest release download url.

Download latest Powershell release for Windows x64 zip version#

The goal of this demo is to convert the static url:

to the real download url (latest version on 2019/12/29):

> $url = ''
> $request = [System.Net.WebRequest]::Create($url)
> $response = $request.GetResponse()
> $realTagUrl = $response.ResponseUri.OriginalString
> $version = $realTagUrl.split('/')[-1].Trim('v')
> $version
> $fileName = "PowerShell-$"
> $realDownloadUrl = $realTagUrl.Replace('tag', 'download') + '/' + $fileName
> $realDownloadUrl
> Invoke-WebRequest -Uri $realDownloadUrl -OutFile $env:TEMP/$fileName


The same method can be applied to retrieve other urls on other sites.


The powershell pre-release doesn't have a static url, so I cannot retrieve the latest v7.0.0-rc.1 download url.