PowerShell/docs/check-apps.md

76 lines
2.0 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *check-apps.ps1* Script
===========================
2022-12-04 10:40:18 +01:00
2024-05-19 10:25:56 +02:00
check-apps.ps1
2022-12-04 10:40:18 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2022-12-04 10:40:18 +01:00
```powershell
2024-05-19 10:25:56 +02:00
2022-12-04 10:40:18 +01:00
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-12-04 10:40:18 +01:00
```powershell
<#
.SYNOPSIS
2023-05-26 12:20:18 +02:00
Query the app status
2022-12-04 10:40:18 +01:00
.DESCRIPTION
2023-09-01 17:53:03 +02:00
This PowerShell script queries the installed applications and prints it.
2022-12-04 10:40:18 +01:00
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./check-apps.ps1
2024-11-08 12:35:11 +01:00
⚠️ 150 Win apps installed, 72 upgrades available, 5 crash dump(s) found
2022-12-04 10:40:18 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-11-08 12:35:11 +01:00
function CountCrashDumps {
2024-05-19 10:25:56 +02:00
[string]$path = Resolve-Path -Path "~\AppData\Local\CrashDumps"
$files = (Get-ChildItem -path "$path\*.dmp" -attributes !Directory)
2024-11-08 12:35:11 +01:00
return $files.Count
2024-05-19 10:25:56 +02:00
}
2022-12-04 10:40:18 +01:00
try {
2024-11-08 12:35:11 +01:00
$status = "✅"
2022-12-04 10:40:18 +01:00
if ($IsLinux) {
2023-12-07 20:24:45 +01:00
Write-Progress "Querying installed applications..."
2023-09-01 17:53:03 +02:00
$numPkgs = (apt list --installed 2>/dev/null).Count
$numSnaps = (snap list).Count - 1
2024-05-19 10:25:56 +02:00
Write-Progress -completed "Done."
2024-11-08 12:35:11 +01:00
$reply = "$numPkgs Debian packages, $numSnaps snaps installed"
2022-12-04 10:40:18 +01:00
} else {
2024-05-19 10:25:56 +02:00
Write-Progress "Querying installed apps..."
2024-11-08 12:35:11 +01:00
$apps = Get-AppxPackage
2024-05-19 10:25:56 +02:00
Write-Progress -completed "Done."
2024-11-08 12:35:11 +01:00
$reply = "$($apps.Count) Win apps installed"
2024-05-19 10:25:56 +02:00
[int]$numNonOk = 0
2024-11-08 12:35:11 +01:00
foreach($app in $apps) { if ($app.Status -ne "Ok") { $numNonOk++ } }
if ($numNonOk -gt 0) { $status = "⚠️"; $reply += ", $numNonOk non-ok" }
2024-05-19 10:25:56 +02:00
[int]$numErrors = (Get-AppxLastError)
2024-11-08 12:35:11 +01:00
if ($numErrors -gt 0) { $status = "⚠️"; $reply += ", $numErrors errors" }
2023-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +02:00
$numUpdates = (winget upgrade --include-unknown).Count - 5
2024-11-08 12:35:11 +01:00
$reply += ", $numUpdates upgrades available"
2023-05-26 12:20:18 +02:00
2024-11-08 12:35:11 +01:00
$numCrashDumps = CountCrashDumps
if ($numCrashDumps -ne 0) { $status = "⚠️"; $reply += ", $numCrashDumps crash dump(s) found" }
2022-12-04 10:40:18 +01:00
}
2024-11-08 12:35:11 +01:00
Write-Host "$status $reply"
2022-12-04 10:40:18 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
2024-11-20 11:52:20 +01:00
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:50)*