diff --git a/scripts/check-drives.ps1 b/scripts/check-drives.ps1 index fc938166..ff3685b7 100755 --- a/scripts/check-drives.ps1 +++ b/scripts/check-drives.ps1 @@ -15,7 +15,7 @@ Author: Markus Fleschutz | License: CC0 #> -param([int64]$minLevel = 10) # 10 GB minimum +param([int64]$minLevel = 10GB) function Bytes2String { param([int64]$number) if ($number -lt 1KB) { return "$number bytes" } @@ -29,26 +29,29 @@ function Bytes2String { param([int64]$number) try { Write-Progress "Querying drives..." $drives = Get-PSDrive -PSProvider FileSystem - $minLevel *= 1GB - Write-Progress -completed " " + Write-Progress -completed "Done." + $status = "✅" + $reply = "" foreach($drive in $drives) { $details = (Get-PSDrive $drive.Name) if ($IsLinux) { $name = $drive.Name } else { $name = $drive.Name + ":" } [int64]$free = $details.Free [int64]$used = $details.Used [int64]$total = ($used + $free) - if ($total -eq 0) { - Write-Host "✅ $name is empty" + $reply += "📂$name is empty " } elseif ($free -eq 0) { - Write-Host "⚠️ $name with $(Bytes2String $total) is full" + $status = "⚠️" + $reply += "📂$name is full ($(Bytes2String $total)) " } elseif ($free -lt $minLevel) { - Write-Host "⚠️ $name with $(Bytes2String $total) is nearly full, $(Bytes2String $free) free" + $status = "⚠️" + $reply += "📂$name is nearly full ($(Bytes2String $free) of $(Bytes2String $total) left) " } else { - [int64]$percent = ($used * 100) / $total - Write-Host "✅ $name at $percent% of $(Bytes2String $total) - $(Bytes2String $free) free" + [int64]$percent = ($free * 100) / $total + $reply += "📂$name has $(Bytes2String $free) of $(Bytes2String $total) left ($percent%) " } } + Write-Host "$status $reply" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/scripts/check-power.ps1 b/scripts/check-power.ps1 index 0a0256d7..08a200f5 100755 --- a/scripts/check-power.ps1 +++ b/scripts/check-power.ps1 @@ -5,7 +5,7 @@ This PowerShell script queries the power status and prints it. .EXAMPLE PS> ./check-power.ps1 - ⚠️ Battery at 9% with power scheme 'HP Optimized' - 54min remaining + ⚠️ Battery 9% only with 54min remaining (power scheme is 'HP Optimized') .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -27,25 +27,25 @@ try { if ($details.BatteryChargeStatus -eq "NoSystemBattery") { $reply = "✅ AC powered" } elseif ($percent -ge 95) { - $reply = "✅ Battery nearly full ($percent%, power scheme '$powerScheme')" + $reply = "✅ Battery nearly full ($percent%, power scheme is '$powerScheme')" } else { - $reply = "✅ Battery charging ($percent%, power scheme '$powerScheme')" + $reply = "✅ Battery charging ($percent%, power scheme is '$powerScheme')" } } else { # must be offline if (($remaining -eq 0) -and ($percent -ge 60)) { - $reply = "✅ Battery $percent% full (power scheme '$powerScheme')" + $reply = "✅ Battery $percent% full (power scheme is '$powerScheme')" } elseif ($remaining -eq 0) { - $reply = "✅ Battery at $percent% (power scheme '$powerScheme')" + $reply = "✅ Battery at $percent% (power scheme is '$powerScheme')" } elseif ($remaining -le 5) { - $reply = "⚠️ Battery at $percent% (power scheme '$powerScheme') - ONLY $($remaining)min remaining" + $reply = "⚠️ Battery $percent% ONLY $($remaining)min remaining (power scheme is '$powerScheme')" } elseif ($remaining -le 30) { - $reply = "⚠️ Battery at $percent% (power scheme '$powerScheme') - only $($remaining)min remaining" + $reply = "⚠️ Battery $percent% only $($remaining)min remaining (power scheme is '$powerScheme')" } elseif ($percent -lt 10) { - $reply = "⚠️ Battery at $percent% (power scheme '$powerScheme') - $($remaining)min remaining" - } elseif ($percent -ge 80) { - $reply = "✅ Battery $percent% full (power scheme '$powerScheme') - $($remaining)min remaining" + $reply = "⚠️ Battery $percent% only with $($remaining)min remaining (power scheme is '$powerScheme') " + } elseif ($percent -ge 90) { + $reply = "✅ Battery $percent% full with $($remaining)min remaining (power scheme is '$powerScheme')" } else { - $reply = "✅ Battery at $percent% (power scheme '$powerScheme') - $($remaining)min remaining" + $reply = "✅ Battery $percent% with $($remaining)min remaining (power scheme is '$powerScheme') " } } } diff --git a/scripts/check-swap-space.ps1 b/scripts/check-swap-space.ps1 index 7815be55..67098785 100755 --- a/scripts/check-swap-space.ps1 +++ b/scripts/check-swap-space.ps1 @@ -48,14 +48,14 @@ try { if ($total -eq 0) { Write-Output "⚠️ No swap space configured" } elseif ($free -eq 0) { - Write-Output "⚠️ Swap space is FULL ($(MB2String $total))" + Write-Output "⚠️ Swap space is full ($(MB2String $total))" } elseif ($free -lt $minLevel) { - Write-Output "⚠️ Swap space has only $(MB2String $free) of $(MB2String $total) free" + Write-Output "⚠️ Swap space has only $(MB2String $free) of $(MB2String $total) left" } elseif ($used -lt 3) { Write-Output "✅ Swap space unused - $(MB2String $free) available" } else { - [int64]$percent = ($used * 100) / $total - Write-Output "✅ Swap space at $percent% of $(MB2String $total) - $(MB2String $free) free" + [int64]$percent = ($free * 100) / $total + Write-Output "✅ Swap space has $(MB2String $free) of $(MB2String $total) left ($percent%)" } exit 0 # success } catch {