rmm-scripts/battery-status.ps1
2023-06-05 11:51:38 -07:00

31 lines
1.1 KiB
PowerShell

#zebra- 6/2/2023
#Script to get current battery percentage & status
$computerSystem = Get-WmiObject -Class Win32_ComputerSystem
$computerModel = $computerSystem.Model
$systemType = $computerSystem.PCSystemType
#check if machine is a Laptop
$isLaptop = ($systemType -eq 2)
if ($isLaptop) {
#Get Battery current stats
$battery = Get-WmiObject -Class Win32_Battery
$batteryPercentage = $battery.EstimatedChargeRemaining
$batteryStatus = $battery.BatteryStatus
$finalStatus = "Battery status: Unknown"
switch ($batteryStatus) {
1 { $finalStatus = "Discharging" }
2 { $finalStatus = "Charging" }
3 { $finalStatus = "Fully charged" }
4 { $finalStatus = "Low"}
5 { $finalStatus = "Critical"}
6 { $finalStatus = "Charging and high" }
7 { $finalStatus = "Charging and low" }
8 { $finalStatus = "Charging and critical"}
9 { $finalStatus = "Undefined"}
10 { $finalStatus = "Partially charged" }
default { $finalStatus = "Battery status: Unknown" }
}
Write-Host "$batteryPercentage% - $finalStatus"
}