mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-21 23:43:25 +01:00
79 lines
2.1 KiB
Markdown
79 lines
2.1 KiB
Markdown
Script: *check-apps.ps1*
|
|
========================
|
|
|
|
check-apps.ps1
|
|
|
|
|
|
Parameters
|
|
----------
|
|
```powershell
|
|
|
|
|
|
[<CommonParameters>]
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
```
|
|
|
|
Script Content
|
|
--------------
|
|
```powershell
|
|
<#
|
|
.SYNOPSIS
|
|
Query the app status
|
|
.DESCRIPTION
|
|
This PowerShell script queries the installed applications and prints it.
|
|
.EXAMPLE
|
|
PS> ./check-apps.ps1
|
|
✅ 119 Windows apps installed, 11 upgrades available
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
.NOTES
|
|
Author: Markus Fleschutz | License: CC0
|
|
#>
|
|
|
|
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
|
|
}
|
|
|
|
try {
|
|
$statusIcon = "✅"
|
|
$statusMsg = ""
|
|
if ($IsLinux) {
|
|
Write-Progress "Querying installed applications..."
|
|
$numPkgs = (apt list --installed 2>/dev/null).Count
|
|
$numSnaps = (snap list).Count - 1
|
|
Write-Progress -completed "Done."
|
|
$statusMsg += "$numPkgs Debian packages, $numSnaps snaps installed"
|
|
} else {
|
|
Write-Progress "Querying installed apps..."
|
|
$Apps = Get-AppxPackage
|
|
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" }
|
|
|
|
$numUpdates = (winget upgrade --include-unknown).Count - 5
|
|
$statusMsg += ", $numUpdates upgrades available"
|
|
|
|
$crashDumps = GetCrashDumps
|
|
if ($crashDumps -ne 0) { $statusIcon = "⚠️"; $statusMsg += ", $crashDumps crash dumps found" }
|
|
}
|
|
Write-Host "$statusIcon $statusMsg"
|
|
exit 0 # success
|
|
} catch {
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of check-apps.ps1 as of 05/19/2024 10:25:17)*
|