Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace System.Management.Automation.Host
- Clear-Host
- function Get-LatestGitHubVersion{
- <#
- .SYNOPSIS
- A function to get the Latest Stable Version of a GitHub repository.
- .DESCRIPTION
- This function web scrapes a GitHub repository and
- parses out the Latest Stable Version.
- This function will return the latest version as a string.
- .PARAMETER repos
- Repository.
- .EXAMPLE
- Get-LatestGitHubVersion 'powershell/powershell'
- Get-LatestGitHubVersion 'audacity/audacity'
- #>
- Param ( [Parameter(Mandatory=1)][string]$repos
- )
- $url = "https://api.github.com/repos/$repos/releases/latest"
- try{
- $tag = Invoke-RestMethod $url
- return $tag.tag_name
- }catch{
- $_.exception | Write-Warning
- return $null
- }
- }
- function Download-LatestGitHubVersion{
- <#
- .SYNOPSIS
- A function to download the Lastest Stable Version of a GitHub repository.
- .DESCRIPTION
- This function web scrapes a GitHub repository and downloads
- the latest stable version. The download will be saved to Users Downloads folder.
- This function will return the full path string of the downloaded file.
- .PARAMETER repos
- Repository.
- .PARAMETER filter
- Filter string for Downloadable file.
- .EXAMPLE
- Download-LatestGitHubVersion 'powershell/powershell' '*win*x64*.msi'
- Download-LatestGitHubVersion 'audacity/audacity' '*64*.exe'
- #>
- Param ( [Parameter(Mandatory=1)][string]$repos,
- [Parameter(Mandatory=1)][string]$filter
- )
- $url = "https://api.github.com/repos/$repos/releases/latest"
- try{
- $tag = Invoke-RestMethod $url
- $latest = $tag.assets | Where-Object { $_.name -like $filter }
- $file = "$HOME\Downloads\$($latest.name)"
- Write-Host $('Dowloading latest release to: ' + $file)
- Invoke-WebRequest $latest.browser_download_url -Out $file
- return $file
- }catch{
- $_.exception | Write-Warning
- return $null
- }
- }
- Get-LatestGitHubVersion 'powershell/powershell'
- Get-LatestGitHubVersion 'audacity/audacity'
- Get-LatestGitHubVersion 'microsoft/typescript'
- Get-LatestGitHubVersion 'notepad-plus-plus/notepad-plus-plus'
- Download-LatestGitHubVersion 'powershell/powershell' '*win*x64*.msi'
- Download-LatestGitHubVersion 'audacity/audacity' '*64*.exe'
- Download-LatestGitHubVersion 'notepad-plus-plus/notepad-plus-plus' '*x64*.exe'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement