PowerShell/scripts/check-apps.ps1

57 lines
1.7 KiB
PowerShell
Raw Normal View History

2023-10-31 12:05:32 +01: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
119 Windows apps installed, 11 upgrades available
2022-12-02 11:48:59 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-05-06 18:48:30 +02:00
function GetCrashDumps {
[string]$path = Resolve-Path -Path "~\AppData\Local\CrashDumps"
$count = 0
$files = (Get-ChildItem -path "$path\*.dmp" -attributes !Directory)
foreach($file in $files) { $count++ }
return $count
}
2022-12-02 11:48:59 +01:00
try {
2024-05-06 18:48:30 +02:00
$statusIcon = ""
$statusMsg = ""
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."
$statusMsg += "$numPkgs Debian packages, $numSnaps snaps installed"
} else {
2024-05-06 18:48:30 +02:00
Write-Progress "Querying installed apps..."
2022-12-28 18:21:43 +01:00
$Apps = Get-AppxPackage
2024-05-06 18:48:30 +02:00
Write-Progress -completed "Done."
$statusMsg = "$($Apps.Count) Win apps installed"
[int]$numNonOk = 0
foreach($App in $Apps) { if ($App.Status -ne "Ok") { $numNonOk++ } }
if ($numNonOk -gt 0) { $statusIcon = "⚠️"; $statusMsg += ", $numNonOk non-ok" }
[int]$numErrors = (Get-AppxLastError)
if ($numErrors -gt 0) { $statusIcon = "⚠️"; $statusMsg += ", $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
$statusMsg += ", $numUpdates upgrades available"
2022-12-04 19:07:18 +01:00
2024-05-06 18:48:30 +02:00
$crashDumps = GetCrashDumps
2024-06-07 20:29:23 +02:00
if ($crashDumps -ne 0) { $statusIcon = "⚠️"; $statusMsg += " - found $crashDumps crash dump(s)" }
}
2024-05-06 18:48:30 +02:00
Write-Host "$statusIcon $statusMsg"
2022-12-02 11:48:59 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}