Skip to content

Instantly share code, notes, and snippets.

@maxkoshevoi
Created April 9, 2021 18:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxkoshevoi/60d7b7910ad6ddcc6e1c9b656a8d0301 to your computer and use it in GitHub Desktop.
Save maxkoshevoi/60d7b7910ad6ddcc6e1c9b656a8d0301 to your computer and use it in GitHub Desktop.
Download latest GitHub release via Powershell
$repoName = "PowerShell/PowerShell"
$assetPattern = "*-win-x64.msi"
$extractDirectory = "C:\Users\Public\Downloads"
$releasesUri = "https://api.github.com/repos/$repoName/releases/latest"
$asset = (Invoke-WebRequest $releasesUri | ConvertFrom-Json).assets | Where-Object name -like $assetPattern
$downloadUri = $asset.browser_download_url
$extractPath = [System.IO.Path]::Combine($extractDirectory, $asset.name)
Invoke-WebRequest -Uri $downloadUri -Out $extractPath
@Joebu
Copy link

Joebu commented Aug 11, 2021

Thanks your example works fine with the powershell repo but when I execute this against my private repository I get the following error on line 11 The request was aborted: The connection was closed unexpectedly.

@sonibla
Copy link

sonibla commented Nov 29, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment