Open theITcloudAdmn opened 1 year ago
Just had a test case where $LASTEXITCODE was "0" but output was empty. So this is probably the safer way to do it:
Set-Location $winGetPath
& .\$winGetBinary list --id $winGetAppId --source $winGetAppSource --accept-source-agreements | Tee-Object -Variable winGetTest
$winGetTestFind = $winGetTest | Select-String -Pattern $winGetAppName
if (($LASTEXITCODE -eq "0") -and (-not([string]::IsNullOrEmpty($winGetTestFind)))) {
Write-Host "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is installed"
Write-LogEntry -logEntry "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is installed" -logID $logID
return @{Result = 'Installed' }
}
else {
Write-Host "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is not installed"
Write-LogEntry -logEntry "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is not installed" -logID $logID
return @{Result = 'Not Installed' }
}
Or without checking exit code:
$winGetTest = & .\$winGetBinary list --id $winGetAppId --source $winGetAppSource --accept-source-agreements
if ($winGetTest -like "*$winGetAppName*") {
Write-Host "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is installed"
Write-LogEntry -logEntry "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is installed" -logID $logID
return @{Result = 'Installed' }
}
else {
Write-Host "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is not installed"
Write-LogEntry -logEntry "The 'WinGet list' command line indicated the '$($winGetAppName)' app, with Id '$($winGetAppId)', is not installed" -logID $logID
return @{Result = 'Not Installed' }
}
I also have a similar error, but when checking/running the "winget.exe list --id ........." command manually, I get an error like "The source requires current machine's geographic region (like "US") to be sent to function properly." (translated from german). I cannot figure out, if and how a I can set a region.
If working on WinSystemLocale not US/EN, this is not going to work:
if ($line -like "*No installed package found*") {
https://github.com/byteben/MEM/blob/e85ebf4181d913701c27a67d22dfaf5790dc4381/Reset-Appx.ps1#L664C35-L664C61For example in german it says:
Maybe a better idea is to work with the exit code of
$winGetTest = & .\$winGetBinary list --id $winGetAppId --source $winGetAppSource --accept-source-agreements
(if this fails, $LASTEXITCODE is -1978335212)For example: