Skip to content

Instantly share code, notes, and snippets.

@sonibla
Created November 29, 2021 10:39
Show Gist options
  • Save sonibla/a60fc31b244ceba3220b9bb33316798c to your computer and use it in GitHub Desktop.
Save sonibla/a60fc31b244ceba3220b9bb33316798c to your computer and use it in GitHub Desktop.
Download assets from private Github releases using PowerShell
$credentials="<github_access_token>"
$repo = "<user_or_org>/<repo_name>"
$file = "<name_of_asset_file>"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "token $credentials")
$releases = "https://api.github.com/repos/$repo/releases"
Write-Host Determining latest release
$id = ((Invoke-WebRequest $releases -Headers $headers | ConvertFrom-Json)[0].assets | where { $_.name -eq $file })[0].id
$download = "https://" + $credentials + ":@api.github.com/repos/$repo/releases/assets/$id"
Write-Host Dowloading latest release
$headers.Add("Accept", "application/octet-stream")
Invoke-WebRequest -Uri $download -Headers $headers -OutFile $file
Write-Host Extracting release files
Expand-Archive $file -Force
Write-Host Cleaning up target dir
Remove-Item "$file" -Force
@sonibla
Copy link
Author

sonibla commented Nov 29, 2021

@Silloky
Copy link

Silloky commented Jul 24, 2022

@sonibla Thank you SO much for this script ! Have been looking for the last 3 hours, and couldn't find anything suitable ! But yours is simply a lifesaver ! Thanks again.

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