Battery status notifier script

My HP laptop is giving problem these days due to some battery issue. Major problem is, it gets shutdown abruptly. Till i manage time to give it to the service center, i wrote a simple script in PowerShell script to notify me that power supply to laptop is down. This script make a beep sound at 4000 Hz for 2.5 seconds interval and a message dialog box.

dialog
If the laptop runs on the battery, the BatteryStatus reports 1, which means that “The battery is discharging”.  The following chart details the meaning of the status of the battery.

Value Meaning
 1 The battery is discharging.
 2 The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.
 3 Fully Charged
 4 Low
 5 Critical
 6 Charging
 7 Charging and High
 8 Charging and Low
 9 Charging and Critical
 10 Undefined
 11 Partially Charged

 

For my purpose, i obtained the battery status from following instance.

(Get-CimInstance win32_battery).batterystatus

I have added a bat file script’s shortcut in startup folder . Whole project is added in my github repository.
The script is shown below.

for powerShell script (pw_battery.ps1)

while(1){
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null;

$var=(Get-CimInstance win32_battery).batterystatus;

    if($var -eq 1){

    [console]::beep(4000,2500) 
    [System.Windows.Forms.MessageBox]::Show("Power supply is removed. Connect it otherwise laptop will get shutdown abruptly." , "Urgent")| out-null ;

    }
}
for batch file (battery.bat)
@ECHO OFF
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden  -NoProfile -File  C:\CustomCmd\pwr_battery.ps1 -ExecutionPolicy RemoteSigned
PAUSE