mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-16 11:40:53 +01:00
Update check-drives.ps1, check-health.ps1, and check-swap-space.ps1
This commit is contained in:
parent
a7b8943e99
commit
26ad83c417
@ -15,23 +15,39 @@
|
|||||||
|
|
||||||
param([int]$MinLevel = 10) # 10 GB minimum
|
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 {
|
try {
|
||||||
$Drives = Get-PSDrive -PSProvider FileSystem
|
$Drives = Get-PSDrive -PSProvider FileSystem
|
||||||
foreach($Drive in $Drives) {
|
foreach($Drive in $Drives) {
|
||||||
$ID = $Drive.Name
|
$ID = $Drive.Name
|
||||||
$Details = (Get-PSDrive $ID)
|
$Details = (Get-PSDrive $ID)
|
||||||
[int]$Free = $Details.Free / 1GB
|
[int64]$Free = $Details.Free
|
||||||
[int]$Used = $Details.Used / 1GB
|
[int64]$Used = $Details.Used
|
||||||
[int]$Total = ($Used + $Free)
|
[int64]$Total = ($Used + $Free)
|
||||||
|
|
||||||
if ($Total -eq 0) {
|
if ($Total -eq 0) {
|
||||||
"✅ Drive $ID is empty."
|
"✅ Drive $ID is empty."
|
||||||
} elseif ($Free -lt $MinLevel) {
|
} 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) {
|
} elseif ($Used -lt $Free) {
|
||||||
"✅ Drive $ID uses $Used GB of $Total GB."
|
"✅ Drive $ID uses $(Bytes2String $Used) of $(Bytes2String $Total)."
|
||||||
} else {
|
} else {
|
||||||
"✅ Drive $ID has $Free GB of $Total GB left."
|
"✅ Drive $ID has $(Bytes2String $Free) of $(Bytes2String $Total) left."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
& "$PSScriptRoot/check-uptime.ps1"
|
|
||||||
& "$PSScriptRoot/check-operating-system.ps1"
|
& "$PSScriptRoot/check-operating-system.ps1"
|
||||||
|
& "$PSScriptRoot/check-uptime.ps1"
|
||||||
& "$PSScriptRoot/check-time-zone.ps1"
|
& "$PSScriptRoot/check-time-zone.ps1"
|
||||||
& "$PSScriptRoot/check-cpu.ps1"
|
& "$PSScriptRoot/check-cpu.ps1"
|
||||||
& "$PSScriptRoot/check-ram.ps1"
|
& "$PSScriptRoot/check-ram.ps1"
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
param([int]$MinLevel = 10) # minimum level in GB
|
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" }
|
if ($Bytes -lt 1000) { return "$($Bytes)GB" }
|
||||||
$Bytes /= 1000
|
$Bytes /= 1000
|
||||||
if ($Bytes -lt 1000) { return "$($Bytes)TB" }
|
if ($Bytes -lt 1000) { return "$($Bytes)TB" }
|
||||||
@ -44,13 +46,13 @@ try {
|
|||||||
if ($Total -eq 0) {
|
if ($Total -eq 0) {
|
||||||
"⚠️ No swap space!"
|
"⚠️ No swap space!"
|
||||||
} elseif ($Free -lt $MinLevel) {
|
} 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) {
|
} elseif ($Used -eq 0) {
|
||||||
"✅ Swap space of $(GB2String $Total) is unused."
|
"✅ Swap space of $(MB2String $Total) is unused."
|
||||||
} elseif ($Used -lt $Free) {
|
} elseif ($Used -lt $Free) {
|
||||||
"✅ Swap space uses $(GB2String $Used) of $(GB2String $Total)."
|
"✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)."
|
||||||
} else {
|
} else {
|
||||||
"✅ Swap space has $(GB2String $Free) of $(GB2String $Total) left."
|
"✅ Swap space has $(MB2String $Free) of $(MB2String $Total) left."
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user