2024-03-28 12:39:23 -07:00
function Get-WinUtilWingetLatest {
<#
. SYNOPSIS
Uses GitHub API to check for the latest release of Winget.
. DESCRIPTION
This function grabs the latest version of Winget and returns the download path to Install-WinUtilWinget for installation.
#>
2024-06-29 01:15:39 +03:00
# Invoke-WebRequest is notoriously slow when the byte progress is displayed. The following lines disable the progress bar and reset them at the end of the function
$PreviousProgressPreference = $ProgressPreference
2024-06-04 20:27:27 -07:00
$ProgressPreference = "silentlyContinue"
2024-08-06 23:35:17 +03:00
try {
2024-03-28 12:39:23 -07:00
# Grabs the latest release of Winget from the Github API for the install process.
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/Winget-cli/releases/latest" -Method Get -ErrorAction Stop
$latestVersion = $response . tag_name #Stores version number of latest release.
2024-06-04 20:27:27 -07:00
$licenseWingetUrl = $response . assets . browser_download_url | Where-Object { $_ -like "*License1.xml" } #Index value for License file.
2024-03-28 12:39:23 -07:00
Write-Host "Latest Version: `t $( $latestVersion ) `n "
2024-06-04 20:27:27 -07:00
Write-Host "Downloading..."
$assetUrl = $response . assets . browser_download_url | Where-Object { $_ -like "*Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" }
2024-03-28 12:39:23 -07:00
Invoke-WebRequest -Uri $licenseWingetUrl -OutFile $ENV:TEMP \ License1 . xml
# The only pain is that the msixbundle for winget-cli is 246MB. In some situations this can take a bit, with slower connections.
Invoke-WebRequest -Uri $assetUrl -OutFile $ENV:TEMP \ Microsoft . DesktopAppInstaller . msixbundle
2024-08-06 23:35:17 +03:00
} catch {
2024-03-28 12:39:23 -07:00
throw [ WingetFailedInstall ]:: new ( 'Failed to get latest Winget release and license' )
}
2024-06-04 20:27:27 -07:00
$ProgressPreference = $PreviousProgressPreference
2024-03-28 12:39:23 -07:00
}