From 3a8a883c00560219616c7bd8ed1fba4a0d6c14ba Mon Sep 17 00:00:00 2001 From: Thomas Redmer Date: Mon, 9 Oct 2023 16:30:39 +0200 Subject: [PATCH 1/2] Fix handling of multiple DesktopAppInstaller versions installed Previously, Microsoft.DesktopAppInstaller packages where alphabetically sorted descending to find the latest one. This led to wrong results, e.g. in this case: C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.4.3161.0_x64__8wekyb3d8bbwe C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.21.2721.0_x64__8wekyb3d8bbwe C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.16.12653.0_x64__8wekyb3d8bbwe --- Reset-Appx.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Reset-Appx.ps1 b/Reset-Appx.ps1 index 136494e..f025202 100644 --- a/Reset-Appx.ps1 +++ b/Reset-Appx.ps1 @@ -554,7 +554,8 @@ Process { Write-LogEntry -logEntry "Testing the WinGet package and other dependancies are installed" -logID $logID try { - $winGetPath = (Get-AppxPackage -AllUsers | Where-Object { $_.Name -eq $winGetPackageName }).InstallLocation | Sort-Object -Descending | Select-Object -First 1 -ErrorAction Stop + $winGetLatestVersion = ((Get-AppxPackage -AllUsers | Where-Object { $_.Name -eq $winGetPackageName }).Version | ForEach-Object { [version]$_ } | Sort-Object -Descending | Select-Object -First 1 -ErrorAction Stop).ToString() + $winGetPath = (Get-AppxPackage -AllUsers | Where-Object { $_.Name -eq $winGetPackageName -and $_.Version -eq $winGetLatestVersion }).InstallLocation } catch { $testWinGetPathFail = $true @@ -863,4 +864,4 @@ end { Write-LogEntry -logEntry "The script completed with errors. Please check the log file for more information" -logID $logID -severity 3 Exit 1 } -} \ No newline at end of file +} From 4618ce70ba8f1a78436d81dc18a6d1e4c8c7b3b0 Mon Sep 17 00:00:00 2001 From: Thomas Redmer Date: Mon, 9 Oct 2023 16:37:02 +0200 Subject: [PATCH 2/2] Add explicit machine scope to Test-WinGetApp Without explicitly specifying the scope to the winget list command, it will query the user scope. We want it to query the machine scope of course. --- Reset-Appx.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Reset-Appx.ps1 b/Reset-Appx.ps1 index f025202..e040da8 100644 --- a/Reset-Appx.ps1 +++ b/Reset-Appx.ps1 @@ -659,12 +659,12 @@ Process { ) try { Write-Host "Checking if '$($winGetAppName)' is installed using Id '$($winGetAppId)'..." - Write-Host "winget.exe list --id $($winGetAppId) --source $($winGetAppSource) --accept-source-agreements" + Write-Host "winget.exe list --id $($winGetAppId) --source $($winGetAppSource) --scope machine --accept-source-agreements" Write-LogEntry -logEntry "Checking if '$($winGetAppName)' is installed using Id '$($winGetAppId)'..." -logID $logID - Write-LogEntry -logEntry "winget.exe list --id '$($winGetAppId)' --source $($winGetAppSource) --accept-source-agreements" -logID $logID + Write-LogEntry -logEntry "winget.exe list --id '$($winGetAppId)' --source $($winGetAppSource) --scope machine --accept-source-agreements" -logID $logID Set-Location $winGetPath - $winGetTest = & .\$winGetBinary list --id $winGetAppId --source $winGetAppSource --accept-source-agreements + $winGetTest = & .\$winGetBinary list --id $winGetAppId --source $winGetAppSource --scope machine --accept-source-agreements foreach ($line in $winGetTest) {