Solved

Batch script to evaulate battery life and take action

Posted on 2014-12-08
3
319 Views
Last Modified: 2014-12-09
I'm having trouble getting this script to work. My plan is to take one course of action if battery life is less than 50% and take another action for battery life is 50% or higher.

set CRITICALLEVEL=50
for /f "skip=1" %%a in ('wmic path Win32_Battery get EstimatedChargeRemaining') do if %%a gtr 0 set BATTERYLEVEL=%%a
if %BATTERYLEVEL% leq %CRITICALLEVEL% goto CRITICAL if %BATTERYLEVEL% gtr %NOPOWERLEVEL% goto UPDATEFIRMWARE


:UPDATEFIRMWARE
Echo Firmware about to install
Echo Battery life is at %BATTERYLEVEL%
goto eof

:CRITICAL
Echo Battery is too low to update
Echo Battery life is at %BATTERYLEVEL%

:EOF
Echo Done

Open in new window


Any help here would be great.
0
Comment
Question by:hpops
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 40488252
Something like this?
@echo off
setlocal
set CriticalLevel=50
set BatteryLevel=-1
for /f %%a in ('wmic.exe path Win32_Battery get EstimatedChargeRemaining ^| findstr.exe /r "[0-9][0-9]*"') do set BatteryLevel=%%a
if "%BatteryLevel%"=="-1" (
	echo No battery found; keep the machine plugged in.
	goto UpdateFirmware
)
echo Battery level is at %BatteryLevel%%%.
if %BatteryLevel% leq %CriticalLevel% (
	echo Battery level is less than %CriticalLevel%, so too low to update.
	pause
	goto :eof
)
:UpdateFirmware
echo Firmware is about to install ...

Open in new window

0
 

Author Comment

by:hpops
ID: 40488659
oBdA,

You nailed it. This works perfectly.

Thanks for your effort.
Dave
0
 

Author Closing Comment

by:hpops
ID: 40488662
Great job on answering this question. Thanks again!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question