2023-10-12 02:22:15 +00:00
|
|
|
#Function to download and update WinGet
|
2023-10-11 20:19:34 +00:00
|
|
|
|
2023-10-30 17:42:58 +00:00
|
|
|
Function Update-WinGet ($WinGetAvailableVersion) {
|
2023-10-11 20:19:34 +00:00
|
|
|
|
2023-10-17 20:35:36 +00:00
|
|
|
$download_string = "-> Downloading WinGet MSIXBundle for App Installer..."
|
|
|
|
$install_string = "-> Installing WinGet MSIXBundle for App Installer..."
|
2023-10-30 23:03:36 +00:00
|
|
|
$success_string = "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully!"
|
|
|
|
$reset_string = "-> WinGet sources reset.`n"
|
|
|
|
$fail_string = "-> Failed to install WinGet MSIXBundle for App Installer...`n"
|
2023-10-12 17:42:01 +00:00
|
|
|
|
2023-10-11 20:19:34 +00:00
|
|
|
#Download WinGet MSIXBundle
|
2023-10-17 20:35:36 +00:00
|
|
|
Write-ToLog $download_string
|
2023-10-11 20:19:34 +00:00
|
|
|
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
2023-10-30 17:42:58 +00:00
|
|
|
$WingetInstaller = "$env:TEMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
|
|
|
Invoke-RestMethod -Uri $WinGetURL -OutFile $WingetInstaller
|
2023-10-11 20:19:34 +00:00
|
|
|
|
|
|
|
#Install WinGet MSIXBundle in SYSTEM context
|
|
|
|
try {
|
2023-10-17 20:35:36 +00:00
|
|
|
Write-ToLog $install_string
|
2023-10-30 17:42:58 +00:00
|
|
|
Add-AppxProvisionedPackage -Online -PackagePath $WingetInstaller -SkipLicense | Out-Null
|
2023-10-17 20:35:36 +00:00
|
|
|
Write-ToLog $success_string "green"
|
2023-10-11 20:19:34 +00:00
|
|
|
|
|
|
|
#Reset WinGet Sources
|
2023-10-30 17:42:58 +00:00
|
|
|
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
|
|
|
|
#If multiple versions, pick most recent one
|
|
|
|
$WingetCmd = $WingetInfo[-1].FileName
|
|
|
|
& $WingetCmd source reset --force
|
|
|
|
Write-ToLog $reset_string "green"
|
|
|
|
|
2023-10-11 20:19:34 +00:00
|
|
|
}
|
|
|
|
catch {
|
2023-10-17 20:35:36 +00:00
|
|
|
Write-ToLog $fail_string "red"
|
2023-10-12 02:22:15 +00:00
|
|
|
Update-StoreApps
|
2023-10-11 20:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#Remove WinGet MSIXBundle
|
2023-10-30 17:42:58 +00:00
|
|
|
Remove-Item -Path $WingetInstaller -Force -ErrorAction SilentlyContinue
|
2023-10-11 20:19:34 +00:00
|
|
|
}
|