From bc9eb5ec0058a133350f244705ae3e2b162d1426 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 8 Oct 2023 03:50:38 +0200 Subject: [PATCH 1/5] ALways check WinGet version at install --- Winget-AutoUpdate-Install.ps1 | 92 +++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 15 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 6ab9df9..abc8098 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -179,22 +179,83 @@ function Install-Prerequisites { } } +#Function to get the winget command regarding execution context (User, System...) +Function Get-WingetCmd { + + #Get WinGet Path (if Admin context) + # Includes Workaround for ARM64 (removed X64 and replaces it with a wildcard) + $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } + + if ($ResolveWingetPath) { + #If multiple version, pick last one + $WingetPath = $ResolveWingetPath[-1].Path + } + + #If running under System or Admin context obtain Winget from Program Files + if((([System.Security.Principal.WindowsIdentity]::GetCurrent().User) -eq "S-1-5-18") -or ($WingetPath)){ + if (Test-Path "$WingetPath\winget.exe") { + $Script:Winget = "$WingetPath\winget.exe" + } + }else{ + #Get Winget Location in User context + $WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue + if ($WingetCmd) { + $Script:Winget = $WingetCmd.Source + } + } + + If(!($Script:Winget)){ + return $false + } + + #Run winget to list apps and accept source agrements (necessary on first run) + & $Winget list --accept-source-agreements -s winget | Out-Null + + return $true + +} + +#Function to get the latest WinGet available version on Github +Function Get-AvailableWinGetVersion { + + #Get latest WinGet info + $WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' + + try { + #Return latest version + return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") + } + catch { + return $false + } + +} + + function Install-WinGet { - Write-Host "`nChecking if Winget is installed" -ForegroundColor Yellow - - #Check Package Install - $TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } - - #Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0 - If ([Version]$TestWinGet.Version -ge "2023.808.2243.0") { - - Write-Host "Winget is Installed" -ForegroundColor Green + Write-Host "`nChecking if Winget is installed/up to date" -ForegroundColor Yellow + #Check available WinGet version, if fail set version to the latest version in 2023-10-08 + $AvailableWinGetVersion = Get-AvailableWinGetVersion + if (!$AvailableWinGetVersion) { + $AvailableWinGetVersion = "1.6.2771" } - Else { - Write-Host "-> Winget is not installed:" + #Check if WinGet is installed, if not set version to dummy... + if (!(Get-WingetCmd)) { + $InstalledWinGetVersion = "0.0.0001" + } + else { + #Get installed WinGet version + $LocalWinGet = & $Winget --version + $InstalledWinGetVersion = $LocalWinGet.Replace("v", "") + } + + #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed + if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) { + + Write-Host "-> Winget is not installed/up to date:" #Check if $WingetUpdatePath exist if (!(Test-Path $WingetUpdatePath)) { @@ -235,10 +296,10 @@ function Install-WinGet { } Remove-Item -Path $VCLibsFile -Force } - + #Download WinGet MSIXBundle Write-Host "-> Downloading Winget MSIXBundle for App Installer..." - $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" + $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") @@ -254,9 +315,10 @@ function Install-WinGet { #Remove WinGet MSIXBundle Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue - } - + else { + Write-Host "-> Winget is up to date: $InstalledWinGetVersion" + } } function Install-WingetAutoUpdate { From 0ed5a5a3b643a3a01311e12ef425d8b87c2d9015 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 8 Oct 2023 11:37:27 +0200 Subject: [PATCH 2/5] Postupdate too --- Winget-AutoUpdate-Install.ps1 | 24 +++++---- .../functions/Get-AvailableWinGetVersion.ps1 | 15 ++++++ .../functions/Invoke-PostUpdateActions.ps1 | 51 ++++++++++++------- 3 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 Winget-AutoUpdate/functions/Get-AvailableWinGetVersion.ps1 diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index abc8098..ef6e9cc 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -209,7 +209,7 @@ Function Get-WingetCmd { } #Run winget to list apps and accept source agrements (necessary on first run) - & $Winget list --accept-source-agreements -s winget | Out-Null + #& $Winget list --accept-source-agreements -s winget | Out-Null return $true @@ -234,9 +234,9 @@ Function Get-AvailableWinGetVersion { function Install-WinGet { - Write-Host "`nChecking if Winget is installed/up to date" -ForegroundColor Yellow + Write-Host "`nChecking if WinGet is installed/up to date" -ForegroundColor Yellow - #Check available WinGet version, if fail set version to the latest version in 2023-10-08 + #Check available WinGet version, if fail set version to the latest version as of 2023-10-08 $AvailableWinGetVersion = Get-AvailableWinGetVersion if (!$AvailableWinGetVersion) { $AvailableWinGetVersion = "1.6.2771" @@ -244,7 +244,7 @@ function Install-WinGet { #Check if WinGet is installed, if not set version to dummy... if (!(Get-WingetCmd)) { - $InstalledWinGetVersion = "0.0.0001" + $InstalledWinGetVersion = "0.0.0000" } else { #Get installed WinGet version @@ -255,7 +255,7 @@ function Install-WinGet { #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) { - Write-Host "-> Winget is not installed/up to date:" + Write-Host "-> WinGet is not installed/up to date (v$InstalledWinGetVersion):" -ForegroundColor Red #Check if $WingetUpdatePath exist if (!(Test-Path $WingetUpdatePath)) { @@ -298,26 +298,30 @@ function Install-WinGet { } #Download WinGet MSIXBundle - Write-Host "-> Downloading Winget MSIXBundle for App Installer..." + Write-Host "-> Downloading WinGet MSIXBundle for App Installer..." $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") #Install WinGet MSIXBundle in SYSTEM context try { - Write-Host "-> Installing Winget MSIXBundle for App Installer..." + Write-Host "-> Installing WinGet MSIXBundle for App Installer..." Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null - Write-host "Winget MSIXBundle for App Installer installed successfully" -ForegroundColor Green + Write-host "Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" -ForegroundColor Green } catch { - Write-Host "Failed to intall Winget MSIXBundle for App Installer..." -ForegroundColor Red + Write-Host "Failed to intall WinGet MSIXBundle for App Installer..." -ForegroundColor Red } #Remove WinGet MSIXBundle Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue } + elseif ($AvailableWinGetVersion -match "-pre") { + Write-Host "-> Available WinGet is a Pre-release: v$AvailableWinGetVersion" -ForegroundColor Yellow + Write-Host "-> Installed WinGet is: v$InstalledWinGetVersion" + } else { - Write-Host "-> Winget is up to date: $InstalledWinGetVersion" + Write-Host "-> WinGet is up to date: v$InstalledWinGetVersion" -ForegroundColor Green } } diff --git a/Winget-AutoUpdate/functions/Get-AvailableWinGetVersion.ps1 b/Winget-AutoUpdate/functions/Get-AvailableWinGetVersion.ps1 new file mode 100644 index 0000000..936da18 --- /dev/null +++ b/Winget-AutoUpdate/functions/Get-AvailableWinGetVersion.ps1 @@ -0,0 +1,15 @@ +#Function to get the latest WinGet available version on Github +Function Get-AvailableWinGetVersion { + + #Get latest WinGet info + $WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' + + try { + #Return latest version + return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") + } + catch { + return $false + } + +} diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index b001bd8..83993f7 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -17,37 +17,54 @@ function Invoke-PostUpdateActions { $null = (New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value ('{0}\logs\install.log' -f $WorkingDir) -Force -Confirm:$False -ErrorAction SilentlyContinue) } - #Check Package Install - Write-ToLog "-> Checking if Winget is installed/up to date" "yellow" - $TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } - - #Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0 - If ([Version]$TestWinGet.Version -ge "2023.808.2243.0") { - - Write-ToLog "-> WinGet is Installed/up to date" "green" + Write-ToLog "-> Checking if WinGet is installed/up to date" "yellow" + #Check available WinGet version, if fail set version to the latest version as of 2023-10-08 + $AvailableWinGetVersion = Get-AvailableWinGetVersion + if (!$AvailableWinGetVersion) { + $AvailableWinGetVersion = "1.6.2771" } - Else { + + #Check if WinGet is installed, if not set version to dummy... + if (!(Get-WingetCmd)) { + $InstalledWinGetVersion = "0.0.0000" + } + else { + #Get installed WinGet version + $LocalWinGet = & $Winget --version + $InstalledWinGetVersion = $LocalWinGet.Replace("v", "") + } + + #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed + if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) { + + Write-ToLog "-> WinGet is not installed/up to date (v$InstalledWinGetVersion):" "red" #Download WinGet MSIXBundle - Write-ToLog "-> Not installed/up to date. Downloading WinGet..." - $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" + Write-ToLog "-> Downloading WinGet MSIXBundle for App Installer..." + $WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") - #Install WinGet MSIXBundle + #Install WinGet MSIXBundle in SYSTEM context try { - Write-ToLog "-> Installing Winget MSIXBundle for App Installer..." + Write-ToLog "-> Installing WinGet MSIXBundle for App Installer..." Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null - Write-ToLog "-> Installed Winget MSIXBundle for App Installer" "green" + Write-ToLog "-> Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" "green" } catch { - Write-ToLog "-> Failed to intall Winget MSIXBundle for App Installer..." "red" + Write-ToLog "-> Failed to intall WinGet MSIXBundle for App Installer..." "red" } #Remove WinGet MSIXBundle Remove-Item -Path "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue - + } + elseif ($AvailableWinGetVersion -match "-pre") { + Write-ToLog "-> Available WinGet is a Pre-release: v$AvailableWinGetVersion" "yellow" + Write-ToLog "-> Installed WinGet is: v$InstalledWinGetVersion" + } + else { + Write-ToLog "-> WinGet is up to date: v$InstalledWinGetVersion" "green" } #Reset Winget Sources @@ -58,7 +75,7 @@ function Invoke-PostUpdateActions { & $WingetPath source reset --force #log - Write-ToLog "-> Winget sources reseted." "green" + Write-ToLog "-> WinGet sources reset." "green" } #Create WAU Regkey if not present From 0254580b23f378d24892841f77811224c0d2a52a Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 8 Oct 2023 23:41:46 +0200 Subject: [PATCH 3/5] Less is more --- Winget-AutoUpdate-Install.ps1 | 94 +++++++------------ .../functions/Invoke-PostUpdateActions.ps1 | 39 ++++---- 2 files changed, 50 insertions(+), 83 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index ef6e9cc..cc52708 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -118,6 +118,22 @@ param( <# FUNCTIONS #> +#Function to get the latest WinGet available version on Github +Function Get-AvailableWinGetVersion { + + #Get latest WinGet info + $WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' + + try { + #Return latest version + return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") + } + catch { + return $false + } + +} + function Install-Prerequisites { Write-Host "`nChecking prerequisites..." -ForegroundColor Yellow @@ -179,59 +195,6 @@ function Install-Prerequisites { } } -#Function to get the winget command regarding execution context (User, System...) -Function Get-WingetCmd { - - #Get WinGet Path (if Admin context) - # Includes Workaround for ARM64 (removed X64 and replaces it with a wildcard) - $ResolveWingetPath = Resolve-Path "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } - - if ($ResolveWingetPath) { - #If multiple version, pick last one - $WingetPath = $ResolveWingetPath[-1].Path - } - - #If running under System or Admin context obtain Winget from Program Files - if((([System.Security.Principal.WindowsIdentity]::GetCurrent().User) -eq "S-1-5-18") -or ($WingetPath)){ - if (Test-Path "$WingetPath\winget.exe") { - $Script:Winget = "$WingetPath\winget.exe" - } - }else{ - #Get Winget Location in User context - $WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue - if ($WingetCmd) { - $Script:Winget = $WingetCmd.Source - } - } - - If(!($Script:Winget)){ - return $false - } - - #Run winget to list apps and accept source agrements (necessary on first run) - #& $Winget list --accept-source-agreements -s winget | Out-Null - - return $true - -} - -#Function to get the latest WinGet available version on Github -Function Get-AvailableWinGetVersion { - - #Get latest WinGet info - $WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' - - try { - #Return latest version - return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") - } - catch { - return $false - } - -} - - function Install-WinGet { Write-Host "`nChecking if WinGet is installed/up to date" -ForegroundColor Yellow @@ -243,19 +206,21 @@ function Install-WinGet { } #Check if WinGet is installed, if not set version to dummy... - if (!(Get-WingetCmd)) { + $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } + if (!$ResolveWingetPath) { $InstalledWinGetVersion = "0.0.0000" } else { - #Get installed WinGet version - $LocalWinGet = & $Winget --version - $InstalledWinGetVersion = $LocalWinGet.Replace("v", "") + #If multiple version, pick last one + $WingetPath = $ResolveWingetPath[-1].Path + $InstalledWinGetVersion = & $WingetPath --version + $InstalledWinGetVersion = $InstalledWinGetVersion.Replace("v", "") } #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) { - Write-Host "-> WinGet is not installed/up to date (v$InstalledWinGetVersion):" -ForegroundColor Red + Write-Host "-> WinGet is not installed/up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available:" -ForegroundColor Red #Check if $WingetUpdatePath exist if (!(Test-Path $WingetUpdatePath)) { @@ -308,6 +273,16 @@ function Install-WinGet { Write-Host "-> Installing WinGet MSIXBundle for App Installer..." Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Write-host "Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" -ForegroundColor Green + + #Reset WinGet Sources + $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } + if ($ResolveWingetPath) { + #If multiple version, pick last one + $WingetPath = $ResolveWingetPath[-1].Path + & $WingetPath source reset --force + #log + Write-Host "-> WinGet sources reset." -ForegroundColor Green + } } catch { Write-Host "Failed to intall WinGet MSIXBundle for App Installer..." -ForegroundColor Red @@ -317,8 +292,7 @@ function Install-WinGet { Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue } elseif ($AvailableWinGetVersion -match "-pre") { - Write-Host "-> Available WinGet is a Pre-release: v$AvailableWinGetVersion" -ForegroundColor Yellow - Write-Host "-> Installed WinGet is: v$InstalledWinGetVersion" + Write-Host "-> WinGet is up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available but only as a Pre-release" -ForegroundColor Yellow } else { Write-Host "-> WinGet is up to date: v$InstalledWinGetVersion" -ForegroundColor Green diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 83993f7..f441316 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -25,20 +25,15 @@ function Invoke-PostUpdateActions { $AvailableWinGetVersion = "1.6.2771" } - #Check if WinGet is installed, if not set version to dummy... - if (!(Get-WingetCmd)) { - $InstalledWinGetVersion = "0.0.0000" - } - else { - #Get installed WinGet version - $LocalWinGet = & $Winget --version - $InstalledWinGetVersion = $LocalWinGet.Replace("v", "") - } + #Check installed WinGet version + Get-WingetCmd + $InstalledWinGetVersion = & $Winget --version + $InstalledWinGetVersion = $InstalledWinGetVersion.Replace("v", "") #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) { - Write-ToLog "-> WinGet is not installed/up to date (v$InstalledWinGetVersion):" "red" + Write-ToLog "-> WinGet is not installed/up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available:" "red" #Download WinGet MSIXBundle Write-ToLog "-> Downloading WinGet MSIXBundle for App Installer..." @@ -51,6 +46,16 @@ function Invoke-PostUpdateActions { Write-ToLog "-> Installing WinGet MSIXBundle for App Installer..." Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null Write-ToLog "-> Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" "green" + + #Reset WinGet Sources + $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } + if ($ResolveWingetPath) { + #If multiple version, pick last one + $WingetPath = $ResolveWingetPath[-1].Path + & $WingetPath source reset --force + #log + Write-ToLog "-> WinGet sources reset." "green" + } } catch { Write-ToLog "-> Failed to intall WinGet MSIXBundle for App Installer..." "red" @@ -60,24 +65,12 @@ function Invoke-PostUpdateActions { Remove-Item -Path "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue } elseif ($AvailableWinGetVersion -match "-pre") { - Write-ToLog "-> Available WinGet is a Pre-release: v$AvailableWinGetVersion" "yellow" - Write-ToLog "-> Installed WinGet is: v$InstalledWinGetVersion" + Write-ToLog "-> WinGet is up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available but only as a Pre-release" "yellow" } else { Write-ToLog "-> WinGet is up to date: v$InstalledWinGetVersion" "green" } - #Reset Winget Sources - $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } - if ($ResolveWingetPath) { - #If multiple version, pick last one - $WingetPath = $ResolveWingetPath[-1].Path - & $WingetPath source reset --force - - #log - Write-ToLog "-> WinGet sources reset." "green" - } - #Create WAU Regkey if not present $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" if (!(test-path $regPath)) { From 45202133635cbacfd19057b137bddd82b9c3b22b Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Mon, 9 Oct 2023 04:58:53 +0200 Subject: [PATCH 4/5] Less log entries --- .../functions/Invoke-PostUpdateActions.ps1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index f441316..9ced4a7 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -26,9 +26,13 @@ function Invoke-PostUpdateActions { } #Check installed WinGet version - Get-WingetCmd - $InstalledWinGetVersion = & $Winget --version - $InstalledWinGetVersion = $InstalledWinGetVersion.Replace("v", "") + $ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } + if ($ResolveWingetPath) { + #If multiple version, pick last one + $WingetPath = $ResolveWingetPath[-1].Path + $InstalledWinGetVersion = & $WingetPath --version + $InstalledWinGetVersion = $InstalledWinGetVersion.Replace("v", "") + } #Check if the current available WinGet isn't a Pre-release and if it's newer than the installed if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) { From bc7d6e6d085f90ce0f6f77ba1d581981fafc9e7a Mon Sep 17 00:00:00 2001 From: GAJ-san Date: Mon, 9 Oct 2023 15:19:05 +0200 Subject: [PATCH 5/5] External Function --- Winget-AutoUpdate-Install.ps1 | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index cc52708..24fcb36 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -118,22 +118,6 @@ param( <# FUNCTIONS #> -#Function to get the latest WinGet available version on Github -Function Get-AvailableWinGetVersion { - - #Get latest WinGet info - $WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' - - try { - #Return latest version - return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") - } - catch { - return $false - } - -} - function Install-Prerequisites { Write-Host "`nChecking prerequisites..." -ForegroundColor Yellow @@ -200,6 +184,7 @@ function Install-WinGet { Write-Host "`nChecking if WinGet is installed/up to date" -ForegroundColor Yellow #Check available WinGet version, if fail set version to the latest version as of 2023-10-08 + . "$PSScriptRoot\Winget-AutoUpdate\functions\Get-AvailableWinGetVersion.ps1" $AvailableWinGetVersion = Get-AvailableWinGetVersion if (!$AvailableWinGetVersion) { $AvailableWinGetVersion = "1.6.2771"