A Windows-based battery monitoring system that alerts users when their laptop battery level falls below 20% or rises above 95%. This helps prevent battery drain and optimize battery health by avoiding overcharging.
- Windows PowerShell implementation
- Audio notifications when battery thresholds are reached
- Desktop notifications via Windows Toast notifications
- Text-to-speech alerts
- Automatic startup configuration
- Customizable battery level thresholds
- Windows 10 or newer
- PowerShell 5.1 or newer
- Right-click on
Install-BatteryMonitor.ps1
and select "Run with PowerShell as Administrator" - Follow the on-screen instructions
- The script will be configured to run at startup automatically
- Right-click on PowerShell and select "Run as Administrator"
- Set execution policy to allow scripts:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
- Add the script to startup:
- Method 1: Create a scheduled task
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File 'C:\path\to\BatteryMonitor.ps1'" $trigger = New-ScheduledTaskTrigger -AtLogon $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable Register-ScheduledTask -TaskName "BatteryMonitorSystem" -Action $action -Trigger $trigger -Settings $settings -Description "Battery Monitor System"
- Method 2: Add to Startup folder
$startup = [Environment]::GetFolderPath('Startup') $shortcut = Join-Path $startup "BatteryMonitor.lnk" $WshShell = New-Object -ComObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($shortcut) $Shortcut.TargetPath = "powershell.exe" $Shortcut.Arguments = "-ExecutionPolicy Bypass -WindowStyle Hidden -File 'C:\path\to\BatteryMonitor.ps1'" $Shortcut.Save()
- Method 1: Create a scheduled task
You can modify the battery thresholds by editing the BatteryMonitor.ps1
file:
# Configuration variables
$LOW_THRESHOLD = 20 # Change to your preferred low battery threshold
$HIGH_THRESHOLD = 95 # Change to your preferred high battery threshold
$CHECK_INTERVAL = 60 # Change how often the script checks battery status (in seconds)
To run the script manually:
- Right-click on PowerShell and select "Run as Administrator"
- Navigate to the script directory
- Execute the script:
.\BatteryMonitor.ps1
If you encounter execution policy issues:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
Ensure you have the required permissions for notifications:
- Go to Windows Settings > System > Notifications & actions
- Make sure notifications are enabled
If the script cannot detect your battery:
- Verify your device has a battery
- Run the following command to check if Windows can detect your battery:
Get-WmiObject -Class Win32_Battery
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.