Add check-battery.ps1

This commit is contained in:
Markus Fleschutz 2022-11-30 08:42:00 +01:00
parent cbf046ba3e
commit 1af1b6acaf
3 changed files with 34 additions and 4 deletions

30
Scripts/check-battery.ps1 Normal file
View File

@ -0,0 +1,30 @@
<#
.SYNOPSIS
Checks the battery status
.DESCRIPTION
This PowerShell script checks and prints the battery status.
.EXAMPLE
PS> ./check-battery
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
Add-Type -Assembly System.Windows.Forms
$Details = [System.Windows.Forms.SystemInformation]::PowerStatus
switch ($Details.PowerLineStatus) {
"Online" { $PowerStatus = "Plugged in to AC power" }
"Offline" { $PowerStatus = "Disconnected from AC power" }
}
switch ($Details.BatteryChargeStatus) {
"NoSystemBattery" { $BatteryStatus = "no system battery" }
default { $BatteryStatus = $Details.BatteryChargeStatus }
}
"$PowerStatus, $BatteryStatus"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -12,15 +12,16 @@
#>
" "
"HARDWARE⭐"
& "$PSScriptRoot/write-green.ps1" " H A R D W A R E"
& "$PSScriptRoot/check-cpu.ps1"
& "$PSScriptRoot/check-ram.ps1"
& "$PSScriptRoot/check-gpu.ps1"
& "$PSScriptRoot/check-bios.ps1"
& "$PSScriptRoot/check-smart-devices.ps1"
& "$PSScriptRoot/check-drives.ps1"
& "$PSScriptRoot/check-battery.ps1"
" "
"SOFTWARE⭐"
& "$PSScriptRoot/write-green.ps1" " S O F T W A R E"
& "$PSScriptRoot/check-operating-system.ps1"
& "$PSScriptRoot/check-uptime.ps1"
& "$PSScriptRoot/check-time-zone.ps1"

View File

@ -39,7 +39,7 @@ if ($Line1 -eq "") {
$Line5 = "Best regards,"
$Line6 = "Markus"
}
write-host ""
WriteLine $Line1 $Speed
WriteLine $Line2 $Speed
WriteLine $Line3 $Speed
@ -49,5 +49,4 @@ WriteLine $Line6 $Speed
WriteLine $Line7 $Speed
WriteLine $Line8 $Speed
WriteLine $Line9 $Speed
write-host ""
exit 0 # success