Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential error when multiple AppInstaller versions installed and add explicit machine scope to Test-WinGetApp #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Reset-Appx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -658,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) {

Expand Down Expand Up @@ -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
}
}
}