Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

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