Forked from MarkTiedemann/download-latest-release.ps1
Last active
April 22, 2025 15:55
-
-
Save Splaxi/fe168eaa91eb8fb8d62eba21736dc88a to your computer and use it in GitHub Desktop.
Download latest GitHub release via Powershell
This file contains hidden or 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
# Download latest dotnet/codeformatter release from github | |
$repo = "jgm/pandoc" | |
$filenamePattern = "*x86_64.zip" | |
$pathExtract = "C:\Tools\pandoc" | |
$innerDirectory = $true | |
$preRelease = $false | |
if ($preRelease) { | |
$releasesUri = "https://api.github.com/repos/$repo/releases" | |
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri)[0].assets | Where-Object name -like $filenamePattern ).browser_download_url | |
} | |
else { | |
$releasesUri = "https://api.github.com/repos/$repo/releases/latest" | |
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url | |
} | |
$pathZip = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $(Split-Path -Path $downloadUri -Leaf) | |
Invoke-WebRequest -Uri $downloadUri -Out $pathZip | |
Remove-Item -Path $pathExtract -Recurse -Force -ErrorAction SilentlyContinue | |
if ($innerDirectory) { | |
$tempExtract = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $((New-Guid).Guid) | |
Expand-Archive -Path $pathZip -DestinationPath $tempExtract -Force | |
Move-Item -Path "$tempExtract\*" -Destination $pathExtract -Force | |
#Move-Item -Path "$tempExtract\*\*" -Destination $location -Force | |
Remove-Item -Path $tempExtract -Force -Recurse -ErrorAction SilentlyContinue | |
} | |
else { | |
Expand-Archive -Path $pathZip -DestinationPath $pathExtract -Force | |
} | |
Remove-Item $pathZip -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I love using your script, thanks for making it! I made my own little reduced version to quickly set up my scripts, thougt I would share it, I made the variables easy to double click and edit