diff --git a/Scripts/check-drives.ps1 b/Scripts/check-drives.ps1 index 74e5df23..1159cb7f 100755 --- a/Scripts/check-drives.ps1 +++ b/Scripts/check-drives.ps1 @@ -15,23 +15,39 @@ param([int]$MinLevel = 10) # 10 GB minimum +function Bytes2String { param([int64]$Bytes) + if ($Bytes -lt 1000) { return "$Bytes bytes" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)KB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)MB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)GB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)TB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)PB" } + $Bytes /= 1000 + if ($Bytes -lt 1000) { return "$($Bytes)EB" } +} + try { $Drives = Get-PSDrive -PSProvider FileSystem foreach($Drive in $Drives) { $ID = $Drive.Name $Details = (Get-PSDrive $ID) - [int]$Free = $Details.Free / 1GB - [int]$Used = $Details.Used / 1GB - [int]$Total = ($Used + $Free) + [int64]$Free = $Details.Free + [int64]$Used = $Details.Used + [int64]$Total = ($Used + $Free) if ($Total -eq 0) { "✅ Drive $ID is empty." } elseif ($Free -lt $MinLevel) { - "⚠️ Drive $ID has only $Free GB of $Total GB left to use!" + "⚠️ Drive $ID has only $(Bytes2String $Free) of $(Bytes2String $Total) left to use!" } elseif ($Used -lt $Free) { - "✅ Drive $ID uses $Used GB of $Total GB." + "✅ Drive $ID uses $(Bytes2String $Used) of $(Bytes2String $Total)." } else { - "✅ Drive $ID has $Free GB of $Total GB left." + "✅ Drive $ID has $(Bytes2String $Free) of $(Bytes2String $Total) left." } } exit 0 # success diff --git a/Scripts/check-health.ps1 b/Scripts/check-health.ps1 index 81c2ef69..33915a85 100755 --- a/Scripts/check-health.ps1 +++ b/Scripts/check-health.ps1 @@ -11,8 +11,8 @@ Author: Markus Fleschutz | License: CC0 #> -& "$PSScriptRoot/check-uptime.ps1" & "$PSScriptRoot/check-operating-system.ps1" +& "$PSScriptRoot/check-uptime.ps1" & "$PSScriptRoot/check-time-zone.ps1" & "$PSScriptRoot/check-cpu.ps1" & "$PSScriptRoot/check-ram.ps1" diff --git a/Scripts/check-swap-space.ps1 b/Scripts/check-swap-space.ps1 index 68e2e745..a46d5a45 100755 --- a/Scripts/check-swap-space.ps1 +++ b/Scripts/check-swap-space.ps1 @@ -16,7 +16,9 @@ param([int]$MinLevel = 10) # minimum level in GB -function GB2String { param([int64]$Bytes) +function MB2String { param([int64]$Bytes) + if ($Bytes -lt 1000) { return "$($Bytes)MB" } + $Bytes /= 1000 if ($Bytes -lt 1000) { return "$($Bytes)GB" } $Bytes /= 1000 if ($Bytes -lt 1000) { return "$($Bytes)TB" } @@ -44,13 +46,13 @@ try { if ($Total -eq 0) { "⚠️ No swap space!" } elseif ($Free -lt $MinLevel) { - "⚠️ Swap space has only $(GB2String $Free) of $(GB2String $Total) left to use!" + "⚠️ Swap space has only $(MB2String $Free) of $(MB2String $Total) left to use!" } elseif ($Used -eq 0) { - "✅ Swap space of $(GB2String $Total) is unused." + "✅ Swap space of $(MB2String $Total) is unused." } elseif ($Used -lt $Free) { - "✅ Swap space uses $(GB2String $Used) of $(GB2String $Total)." + "✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)." } else { - "✅ Swap space has $(GB2String $Free) of $(GB2String $Total) left." + "✅ Swap space has $(MB2String $Free) of $(MB2String $Total) left." } exit 0 # success } catch {