Get the download url of the latest GitHub release using PowerShell

When we want to download the latest version of a GitHub release, we often do it manually from, but there are times when we need this to be an automatic process, either because we must do it on many computers or should it be done without any user interaction. For these scenarios, we can make use of the following PowerShell script:

function Get-Last-GitHub-Release-Url {
    [Parameter(Mandatory = $TRUE)]

    [Parameter(Mandatory = $TRUE)]

  $releasesUri = "$GitHubRepository/releases/latest";
  $response = Invoke-RestMethod -Method "GET" -Uri $releasesUri;
  $assets = $response.assets;
  $lastRelease = $assets | Where-Object "name" -Match "$FilenamePattern";
  return $lastRelease.browser_download_url;

This function receives 2 parameters:

  1. GitHubRepository

    This is the repository identifier, we can get it from the repository webpage, for example:

    In the repository:

    The identifier is:


  2. FilenamePattern

    This is the filename pattern of the file that we want to download, for example:

    Open the releases section of the repository

    We will see a list of all the files of that release, something like this:

    │── hugo_0.105.0_linux-amd64.tar.gz
    │── hugo_0.105.0_openbsd-amd64.tar.gz
    │── hugo_extended_0.105.0_linux-amd64.tar.gz
    │── hugo_extended_0.105.0_openbsd-amd64.tar.gz

    So, if I want to get the url of the release for Windows x64:

    Just replace the version of the file with a “.” (dot/period) metacharacter:


And that’s all, now we can use the PowerShell function to get the download url of the release of that GitHub repository:

Get-Last-GitHub-Release-Url -GitHubRepository "gohugoio/hugo" -FilenamePattern "hugo_extended_(.+)";