The BurntToast PSGallery module provides Toast notifications when the computer is unplugged below 50% or plugged above 75%. This range maximizes the available charging cycles for the laptop battery, supposedly 2000 versus 200, for charging from 0 - 100% regularly.
- The best approach is to fully charge the battery and then remove from the laptop to prevent degradation from higher temperature operation.
- Second best is to always leave the laptop plugged in, since modern laptops will stop charging at 100%. There is some risk of higher temperature degradation of the battery.
If the laptop is left plugged in and laptop stops charging, Toast notifications will not be issued since fully charged is a reasonably good condition. Between 75 and fully charged, toast notifications will repeat every 10 minutes.
Clone the git repository into a convenient location and change to the cloned directory.
git clone https://github.com/jfishe/battery.git # Add path to battery destination if desired.
cd battery # The following commands assume this current working directory.
Use git pull
to update to a newer version when available or clone the
repository again.
Setup a local NuGet repository on a shared location. Google Drive is used as an
example. You can use any valid name for the Powershell
directory and
LocalRepo1
. LocalRepo1
should be trusted so you can Install-Module from
there.
mkdir "$env:USERPROFILE\Google Drive\Powershell"
Register-PSRepository -Name LocalRepo1 -SourceLocation "$env:USERPROFILE\Google Drive\Powershell" -InstallationPolicy Trusted
Publish-Module cloned
repository to the shared location. Repeat this step after git pull
on the
battery.git repository.
Publish-Module -Path .\ScheduleTask_Test-IsOnBattery -Repository "LocalRepo1"
Test-ModuleManifest
checks the .psd1
file and reports results similar to
the following. This step is not necessary but useful for me when I make
changes.
Test-ModuleManifest .\ScheduleTask_Test-IsOnBattery.psd1 | Format-List -Force
Name : ScheduleTask_Test-IsOnBattery
Path : C:\Users\fishe\Documents\Scripts\battery\ScheduleTask_Test-IsOnBattery\ScheduleTask
_Test-IsOnBattery.psd1
Description : Create/manage Task Scheduler entry to monitor battery charging and maximize
battery lifetime.
ModuleType : Script
Version : 0.2.2
NestedModules : {}
ExportedFunctions : {New-BurntToastNotification, Register-BatteryMonitor, Unregister-BatteryMonitor,
Test-IsOnBattery}
ExportedCmdlets :
ExportedVariables :
ExportedAliases :
Install the module in the CurrentUser
location in $env:PSModulePath
and make help available:
- Install BurntToast, if not already. Instructions are available at BurntToast.
- Then install
ScheduleTask_Test-IsOnBattery
:
Install-Module -Name ScheduleTask_Test-IsOnBattery -Repository LocalRepo1 -Scope CurrentUser
To make the help available and add Battery Monitor
to the Task Scheduler
app:
Import-Module ScheduleTask_Test-IsOnBattery
Register-BatteryMonitor
Refer to help for additional details:
Get-Help Register-BatteryMonitor
Get-Help Test-IsOnBattery
Get-Help Unregister-BatteryMonitor
- BurntToast
should be installed under the
CurrentUser
if not already. PSGallery may need to be added as a TrustedPSRepository
. - ScheduledTasks should be installed by default under Windows 10. It provides the cmdlets used to interact with Task Scheduler.
- platyPS for conversion of Markdown help files to XML MAML format.
- https://github.com/PowerShell/PowerShell-Docs/blob/live/appveyor.ps1
- Setting up an Internal PowerShellGet Repository provides instructions for setting up NuGet creating a local repository such as LocalRepo1.
- petri building battery manager Powershell demonstrated how to access the battery status using
Get-WmiObject
. - fossbytes should i keep laptop battery plugged all time harmful provides the rationale for the charging range.
- platyPS for conversion of Markdown help files to XML MAML format.
Refactor to use ScheduledTasks module to generate Task Scheduler entry. Remove XML string that was exported from Task Schedule.
Remove BurntToast from exported functions as it is available in the environment by default.
Add Write-Verbose statement to echo the current state.
Automate publish-module with PSDeploy.
TODO: Replace WMI with CIM call.
- Use platyPS to generate XML MAML format help files. Markdown version in ./docs.
- Add module installation instructions to README.
- Convert scripts into functions and combine in a module.
- Create script module manifest.
- Change to Powershell -ExecutionPolicy Bypass. Set-ExecutionPolicy does not need to be changed to Bypass for script to run as this can be set by Powershell Param.
- Combine Get-WmiObject calls into $BatteryStatus.
- Change sleep from 600 seconds to Param $sleep with default a 600 seconds.
- The Task Scheduler XML needs to contain the current computer name and user name. Replace Task.Triggers.LogonTrigger.UserID with values from the environment variables.
- Add MIT license. Same as dependency.
- Fix README to align with fully charged notifications.
- Refactor to reduce number of -NOT statements and delete unused statements.
- Bug fix to use charging status instead of > 99% to suppress unplug warning.
- Bug fix to formatting of Task Scheduler description.
- Add specific exception and catch logic to ScheduleTask.ps1.
- Add feature to prompt user to delete old version when running ScheduleTask.ps1.