Download assets from private Github releases using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 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
I have to give credit to @maxim (https://gist.github.com/maxim/6e15aa45ba010ab030c4) and @bmils (https://github.community/t/how-to-download-latest-private-github-release-with-powershell-script/170605)
My script is basically just a mix of their scripts