[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Batch script to evaulate battery life and take action

Posted on 2014-12-08
3
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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