User Tools

Site Tools


powershell:misc:cheapups

Poor mans UPS alarm

I have a UPS witch does not have any way to report if the power is gone, however it's connected as “Battery” via USB. This small powershell scripts runs as a schedule every 5 minutes, and sends me an SMS if the power changes.

$Battery = Get-WmiObject -Query "Select * From Win32_Battery" -Namespace "root\Cimv2"
 
$OldStatus = Get-Content "UPSSTATUS.TXT"
 
if ($OldStatus -ne $Battery.BatteryStatus)
{
    $Battery.BatteryStatus | Set-Content "UPSSTATUS.TXT"
    Write-Host "Status Changed"
     SendSMS $Battery.BatteryStatus
}
powershell/misc/cheapups.txt · Last modified: 2018/12/04 10:57 by admin