PowerShell/scripts/check-apps.ps1

54 lines
1.6 KiB
PowerShell
Raw Normal View History

2024-10-01 15:11:03 +02:00
<#
2022-12-02 11:48:59 +01:00
.SYNOPSIS
2023-04-11 10:48:59 +02:00
Query the app status
2022-12-02 11:48:59 +01:00
.DESCRIPTION
This PowerShell script queries the installed applications and prints it.
2022-12-02 11:48:59 +01:00
.EXAMPLE
2023-08-06 21:35:36 +02:00
PS> ./check-apps.ps1
2024-09-10 12:58:30 +02:00
150 Win apps installed, 72 upgrades available, 5 crash dump(s) found
2022-12-02 11:48:59 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-09-10 12:58:30 +02:00
function CountCrashDumps {
2024-05-06 18:48:30 +02:00
[string]$path = Resolve-Path -Path "~\AppData\Local\CrashDumps"
$files = (Get-ChildItem -path "$path\*.dmp" -attributes !Directory)
2024-09-10 12:58:30 +02:00
return $files.Count
2024-05-06 18:48:30 +02:00
}
2022-12-02 11:48:59 +01:00
try {
2024-09-10 12:58:30 +02:00
$status = ""
if ($IsLinux) {
Write-Progress "Querying installed applications..."
2023-08-16 22:18:41 +02:00
$numPkgs = (apt list --installed 2>/dev/null).Count
$numSnaps = (snap list).Count - 1
2024-05-06 18:48:30 +02:00
Write-Progress -completed "Done."
2024-09-10 12:58:30 +02:00
$reply = "$numPkgs Debian packages, $numSnaps snaps installed"
} else {
2024-05-06 18:48:30 +02:00
Write-Progress "Querying installed apps..."
2024-09-10 12:58:30 +02:00
$apps = Get-AppxPackage
2024-05-06 18:48:30 +02:00
Write-Progress -completed "Done."
2024-09-10 12:58:30 +02:00
$reply = "$($apps.Count) Win apps installed"
2024-05-06 18:48:30 +02:00
[int]$numNonOk = 0
2024-09-10 12:58:30 +02:00
foreach($app in $apps) { if ($app.Status -ne "Ok") { $numNonOk++ } }
if ($numNonOk -gt 0) { $status = "⚠️"; $reply += ", $numNonOk non-ok" }
2024-05-06 18:48:30 +02:00
[int]$numErrors = (Get-AppxLastError)
2024-09-10 12:58:30 +02:00
if ($numErrors -gt 0) { $status = "⚠️"; $reply += ", $numErrors errors" }
2023-01-31 13:14:37 +01:00
2024-05-06 18:48:30 +02:00
$numUpdates = (winget upgrade --include-unknown).Count - 5
2024-09-10 12:58:30 +02:00
$reply += ", $numUpdates upgrades available"
2022-12-04 19:07:18 +01:00
2024-09-10 12:58:30 +02:00
$numCrashDumps = CountCrashDumps
if ($numCrashDumps -ne 0) { $status = "⚠️"; $reply += ", $numCrashDumps crash dump(s) found" }
}
2024-09-10 12:58:30 +02:00
Write-Host "$status $reply"
2022-12-02 11:48:59 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}