Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • VirtualBox
  • VMware
  • Windows
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • VirtualBox
  • VMware
  • Windows
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

Download Artifacts from a Latest GitHub Release with PowerShell

October 31, 2022
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

Using PowerShell to Retrieve Latest Package Url from GitHub

Lately I’ve been working on an application for which the releases are published on GitHub, and I wanted to use PowerShell to always downloads the latest release.

It turned out that downloading the artifacts for a specific version is easy, we can simply build an URL with the version number to access the artifact. However, there is no direct URL to download artifacts from the latest release, so we need a bit of logic in PowerShell to do that.

Link structure

We can access a particular release with a URL like https://github.com/<user>/<repo>/releases/tag/v1.x.x. (The part after tag/ is what we specified when we created the release.)

Bg2239
Note And there is this URL, which always takes us to the latest release of a project: https://github.com/user/repo/releases/latest.

Artifacts from this particular release can be downloaded with the URL https://github.com/<user>/<repo>/releases/download/v1.x.x/myArtifact.zip

Bg2240

Getting the latest version from GitHub

Take a look the link of zlib project https://github.com///releases/latest.

  • <user> = madler
  • <repo> = zlib

The following example demonstrates this by fetching the latest Windows x64 release .zip file of the PowerShell: https://github.com/PowerShell/PowerShell/releases/latest

Bg2238
$url = 'https://github.com/PowerShell/PowerShell/releases/latest'
$request = [System.Net.WebRequest]::Create($url)
$response = $request.GetResponse()
$tagUrl = $response.ResponseUri.OriginalString
$version = $tagUrl.split('/')[-1].Trim('v')
$fileName = "PowerShell-$version-win-x64.zip"

###Create the download link
$downloadUrl = $tagUrl.Replace('tag', 'download') + '/' + $fileName

###Create a folder then download to the temp folder
New-Item -Path $env:TEMP/pwsh -ItemType Directory -Force
Invoke-WebRequest -Uri $downloadUrl -OutFile $env:TEMP/pwsh/$fileName  

###Open the destination folder
Invoke-Item $env:TEMP/pwsh

Downloading the latest version of PowerShell from GitHub using PowerShell.

Bg2241

Once done, you can see the package is saved in the destination folder.

Bg2242
ADVERTISEMENT
5/5 - (1 vote)
Previous Post

How to Download Artifacts from a Latest GitHub Release with Bash

Next Post

How to Download the Latest Package from GitHub using PowerShell

Related Posts

Ftr38

[WinForms] Creating GUIs in Windows PowerShell with WinForms

November 15, 2023
Ftr21

Converting DateTime Obtained from Microsoft Graph Call to PowerShell Date and Time Format

October 21, 2023
Ftr21

Translate Microsoft 365 License GUIDs to Product Names in PowerShell Microsoft Graph

October 19, 2023
Ftr21

How to Get an Access Token for Microsoft Graph PowerShell / API

November 27, 2023
Ftr21

Getting Access Token for Microsoft Graph

November 27, 2023
Ftr5

How to Copy Files without Changing Date Creation Time on Windows

November 27, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • [WinForms] Creating GUIs in Windows PowerShell with WinForms
  • Converting DateTime Obtained from Microsoft Graph Call to PowerShell Date and Time Format
  • Translate Microsoft 365 License GUIDs to Product Names in PowerShell Microsoft Graph

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2023 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory