mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-21 17:38:19 +02:00
Update check-battery.ps1, check-drives.ps1, and check-swap-space.ps1
This commit is contained in:
parent
86463af566
commit
c83f590247
@ -17,18 +17,20 @@ try {
|
|||||||
} else {
|
} else {
|
||||||
Add-Type -Assembly System.Windows.Forms
|
Add-Type -Assembly System.Windows.Forms
|
||||||
$Details = [System.Windows.Forms.SystemInformation]::PowerStatus
|
$Details = [System.Windows.Forms.SystemInformation]::PowerStatus
|
||||||
if ($Details.BatteryChargeStatus -eq "NoSystemBattery") {
|
$Status = "✅"
|
||||||
$BatteryStatus = "No battery"
|
|
||||||
} else {
|
|
||||||
[int]$Percent = 100*$Details.BatteryLifePercent
|
|
||||||
[int]$Remaining = $Details.BatteryLifeRemaining / 60
|
|
||||||
$BatteryStatus = "Battery $Percent%, $Remaining min left"
|
|
||||||
}
|
|
||||||
switch ($Details.PowerLineStatus) {
|
switch ($Details.PowerLineStatus) {
|
||||||
"Online" { $PowerStatus = "plugged in to AC power" }
|
"Online" { $Power = "AC powered" }
|
||||||
"Offline" { $PowerStatus = "AC power unplugged" }
|
"Offline" { $Power = "No AC power" }
|
||||||
}
|
}
|
||||||
"✅ $BatteryStatus, $PowerStatus"
|
if ($Details.BatteryChargeStatus -eq "NoSystemBattery") {
|
||||||
|
$Battery = "no system battery"
|
||||||
|
} else {
|
||||||
|
[int]$Percent = 100 * $Details.BatteryLifePercent
|
||||||
|
[int]$Remaining = $Details.BatteryLifeRemaining / 60
|
||||||
|
if ($Remaining -lt 30) { $Status = "⚠️" }
|
||||||
|
$Battery = "$Percent% battery life, $Remaining min. left"
|
||||||
|
}
|
||||||
|
"$Status $Power, $Battery"
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -42,12 +42,14 @@ try {
|
|||||||
|
|
||||||
if ($Total -eq 0) {
|
if ($Total -eq 0) {
|
||||||
"✅ Drive $ID is empty"
|
"✅ Drive $ID is empty"
|
||||||
|
} elseif ($Free -eq 0) {
|
||||||
|
"⚠️ Drive $ID with $(Bytes2String $Total) is full!"
|
||||||
} elseif ($Free -lt $MinLevel) {
|
} elseif ($Free -lt $MinLevel) {
|
||||||
"⚠️ Drive $ID has only $(Bytes2String $Free) of $(Bytes2String $Total) left to use!"
|
"⚠️ Drive $ID with $(Bytes2String $Total) is nearly full ($(Bytes2String $Free) free)!"
|
||||||
} elseif ($Used -lt $Free) {
|
} elseif ($Used -lt $Free) {
|
||||||
"✅ Drive $ID uses $(Bytes2String $Used) of $(Bytes2String $Total)"
|
"✅ Drive $ID uses $(Bytes2String $Used) of $(Bytes2String $Total)"
|
||||||
} else {
|
} else {
|
||||||
"✅ Drive $ID has $(Bytes2String $Free) free of $(Bytes2String $Total)"
|
"✅ Drive $ID has $(Bytes2String $Free) of $(Bytes2String $Total) free"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
Specifies the minimum level (10 GB by default)
|
Specifies the minimum level (10 GB by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./check-swap-space
|
PS> ./check-swap-space
|
||||||
✅ Swap space uses 63 GB of 1856 GB.
|
✅ Swap space uses 63GB of 1856GB
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -45,14 +45,16 @@ try {
|
|||||||
}
|
}
|
||||||
if ($Total -eq 0) {
|
if ($Total -eq 0) {
|
||||||
"⚠️ No swap space configured!"
|
"⚠️ No swap space configured!"
|
||||||
|
} elseif ($Free -eq 0) {
|
||||||
|
"⚠️ Swap space of $(MB2String $Total) is full!"
|
||||||
} elseif ($Free -lt $MinLevel) {
|
} elseif ($Free -lt $MinLevel) {
|
||||||
"⚠️ Only $(MB2String $Free) of $(MB2String $Total) swap space left to use!"
|
"⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)!"
|
||||||
} elseif ($Used -eq 0) {
|
} elseif ($Used -eq 0) {
|
||||||
"✅ Swap space with $(MB2String $Total) reserved"
|
"✅ Swap space with $(MB2String $Total) reserved"
|
||||||
} elseif ($Used -lt $Free) {
|
} elseif ($Used -lt $Free) {
|
||||||
"✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)"
|
"✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)"
|
||||||
} else {
|
} else {
|
||||||
"✅ Swap space has $(MB2String $Free) of $(MB2String $Total) left to use"
|
"✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free"
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user