cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
CyberCitizen
Honored Sweeper
Hi Lansweeper Guru's,

I am looking at a way of tracking our laptop battery status across the fleet of laptops (approx 350).

What we are finding is the batteries are failing just after the warranty period etc. What I am looking to do is create a Lansweeper Report that checks the battery design capacity vs the full charge capacity.

Something we can monitor etc and gives us the ability to raise warranty battery jobs before the devices fail/fall out of warranty as we also donate the laptops after the 3 years of use etc. So would prefer they be in decent working condition etc.

You can pull the information from the devices using the following command lines.

Powershell Get-WmiObject -Namespace 'root\wmi' -Query 'select DesignedCapacity from BatteryStaticData' | Find "DesignedCapacity"

Powershell Get-WmiObject -Namespace 'root\wmi' -Query 'select FullChargedCapacity from BatteryFullChargedCapacity' | Find "FullChargedCapacity"

Would love to see something like this actually captured by Lansweeper, eg the Designed Capacity and then every 30 days etc it checks the FullChargedCapacity to compare, keeps a little log etc of the last few FullChargedCapacity etc so we can monitor battery degradation.
7 REPLIES 7
dmchandrasinghe
Engaged Sweeper II

Hi @CyberCitizen,
I have same requirement to check battery capacity due power continues interruption. Can you guide me how to save above script.

Dinusha Chandrasinghe wrote:
Hi CyberCitizen,
I have same requirement to check battery capacity due power continues interruption. Can you guide me how to save above script.


Sure, you can already see the deployment script that I run on our fleet on machines above.

You will need to add those two custom scanning paths in your registry. So when you deploy that first script to the machine make sure you tell it to rescan the asset.

That writes the data into the registry for us to be able to scan, then if you use the following report you should be able to pull a list of machines battery statuses to look at warranty replacements etc before they drop out of warranty.

Select Top 1000000 tsysOS.Image As icon,
tblAssets.AssetID,
tblAssets.AssetName,
tblAssetCustom.Model,
tblAssets.Username,
SubQuery2.Value As [Battery Design Capacity],
SubQuery1.Value As [Battery Capacity],
Case
When SubQuery1.Value < '30000' Then '#ffadad'
When SubQuery1.Value < '35000' Then '#fff1ad'
When SubQuery1.Value > '35000' Then '#d4f4be'
End As backgroundcolor,
tblWarrantyDetails.WarrantyEndDate,
SubQuery1.Lastchanged,
TsysLastscan.Lasttime As LastRegistryScan,
tblAssets.Lastseen,
Case
When TsysLastscan.Lasttime < GetDate() - 1 Then
'Last registry scan more than 24 hours ago! Scanned registry information may not be up-to-date. Try rescanning this machine.'
End As Comment
From tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysOS On tsysOS.OScode = tblAssets.OScode
Inner Join TsysLastscan On tblAssets.AssetID = TsysLastscan.AssetID
Inner Join TsysWaittime On TsysWaittime.CFGCode = TsysLastscan.CFGcode
Left Join (Select Top 1000000 tblRegistry.AssetID,
tblRegistry.Regkey,
tblRegistry.Valuename,
tblRegistry.Value,
tblRegistry.Lastchanged
From tblRegistry
Where tblRegistry.Regkey Like '%SOFTWARE\lansweeper' And
tblRegistry.Valuename = 'BatteryCapacity') SubQuery1 On
SubQuery1.AssetID = tblAssets.AssetID
Left Join (Select Top 1000000 tblRegistry.AssetID,
tblRegistry.Regkey,
tblRegistry.Valuename,
tblRegistry.Value,
tblRegistry.Lastchanged
From tblRegistry
Where tblRegistry.Regkey Like '%SOFTWARE\lansweeper' And
tblRegistry.Valuename = 'BatteryDesignedCapacity') SubQuery2 On
SubQuery2.AssetID = tblAssets.AssetID
Inner Join lansweeperdb.dbo.tblWarranty On tblAssets.AssetID =
tblWarranty.AssetId
Inner Join lansweeperdb.dbo.tblWarrantyDetails On tblWarranty.WarrantyId =
tblWarrantyDetails.WarrantyId
Where Case
When SubQuery1.Valuename Is Not Null And SubQuery1.Valuename <> ''
Then 'Yes'
Else 'No'
End = 'Yes' And tblAssetCustom.State = 1 And TsysWaittime.CFGname = 'registry'
Order By [Battery Capacity],
tblAssets.Domain,
tblAssets.AssetName
Hendrik_VE
Champion Sweeper III
Nice job Michael! Now I know that it's time for a new battery for my laptop 🙂
We regularly use the same approach here, writing powershell output to regkeys or eventlogs. Unfortunately, there's no 'standard' way for custom scanning.

Can't you add 'batterydesignedcapacity' as a second subquery?

And for colour coding, I think you must use this:

Case
When SubQuery1.Value < '30000' Then '#ffadad'
When SubQuery1.Value < '35000' Then '#fff1ad'
When SubQuery1.Value > '40000' Then '#d4f4be'
End As backgroundcolor

And congrats on the 4 years Esben, still feels like yesterday
Hendrik.VE wrote:
Nice job Michael! Now I know that it's time for a new battery for my laptop 🙂
We regularly use the same approach here, writing powershell output to regkeys or eventlogs. Unfortunately, there's no 'standard' way for custom scanning.

Can't you add 'batterydesignedcapacity' as a second subquery?

And for colour coding, I think you must use this:

Case
When SubQuery1.Value < '30000' Then '#ffadad'
When SubQuery1.Value < '35000' Then '#fff1ad'
When SubQuery1.Value > '40000' Then '#d4f4be'
End As backgroundcolor

And congrats on the 4 years Esben, still feels like yesterday

Thank you but that goes above my skill set, that report code was stolen from another report and tweaked and got it working some how :P.
CyberCitizen
Honored Sweeper
Thanks Esben & congrats on the 4 years at Lansweeper.

Unfortunately, that report mostly ended up with blank data for me.



I did end up creating a deployment package that saves the data to the registry.

<?xml version="1.0" encoding="utf-8"?>
<Package>
<Name>CMD.Write Battery Info to Registry</Name>
<Description></Description>
<ShutdownOption>0</ShutdownOption>
<ShutdownTime>0</ShutdownTime>
<MaxDuration>900</MaxDuration>
<Rescan>True</Rescan>
<RunMode>2</RunMode>
<Steps>
<Step>
<Nr>1</Nr>
<Name>Writes Battery Designed Capacity</Name>
<Type>2</Type>
<ReturnCodes>0,1641,3010</ReturnCodes>
<Success>-1</Success>
<Failure>-1</Failure>
<Path></Path>
<Parameters></Parameters>
<MSIParameters></MSIParameters>
<MSIName></MSIName>
<MSIVersion></MSIVersion>
<Command>cd %tmp% &amp; Powershell Get-WmiObject -Namespace 'root\wmi' -Query 'select DesignedCapacity from BatteryStaticData' &gt; battery.txt &amp; if %errorlevel%==0 (findstr /l /b " DesignedCapacity " battery.txt &gt; id.txt &amp; for /f "tokens=2 delims=: " %a in (id.txt) do (reg add HKLM\Software\Lansweeper /v BatteryDesignedCapacity /t REG_SZ /d %a /f)) &amp; del /f id.txt &amp; del /f battery.txt</Command>
<EditMode>False</EditMode>
<Conditions />
</Step>
<Step>
<Nr>2</Nr>
<Name>Writes Battery Capacity</Name>
<Type>2</Type>
<ReturnCodes>0,1641,3010</ReturnCodes>
<Success>-2</Success>
<Failure>-3</Failure>
<Path></Path>
<Parameters></Parameters>
<MSIParameters></MSIParameters>
<MSIName></MSIName>
<MSIVersion></MSIVersion>
<Command>cd %tmp% &amp; Powershell Get-WmiObject -Namespace 'root\wmi' -Query 'select FullChargedCapacity from BatteryFullChargedCapacity' &gt; battery.txt &amp; if %errorlevel%==0 (findstr /l /b " FullChargedCapacity " battery.txt &gt; id.txt &amp; for /f "tokens=2 delims=: " %a in (id.txt) do (reg add HKLM\Software\Lansweeper /v BatteryCapacity /t REG_SZ /d %a /f)) &amp; del /f id.txt &amp; del /f battery.txt</Command>
<EditMode>False</EditMode>
<Conditions />
</Step>
</Steps>
<SoftwareVersion>8.4.100.9</SoftwareVersion>
</Package>


I then have the following report which checks against these keys to see what the current battery status max charge is. I would like to have the max capacity in the report as well but don't think you can have custom scanning results on separate columns without having seperate entries / rows for the machine, is that correct?

Any that show on this report with limited capacity I am then running a Windows 10 Battery Report to look at battery capacity drops etc.

powercfg /batteryreport /output "\\SERVERNAME\Apps$\Battery Reports\%COMPUTERNAME%.Battery.Report.html"

What I am having trouble with is colour coding this report.

Select Top 1000000 tsysOS.Image As icon,
tblAssets.AssetID,
tblAssets.AssetName,
tblAssets.Domain,
tblAssets.Username,
SubQuery1.Value As [Battery Capacity],
tblWarrantyDetails.WarrantyEndDate,
SubQuery1.Lastchanged,
TsysLastscan.Lasttime As LastRegistryScan,
tblAssets.Firstseen,
tblAssets.Lastseen,
tblAssets.Lasttried,
Case
When TsysLastscan.Lasttime < GetDate() - 1 Then
'Last registry scan more than 24 hours ago! Scanned registry information may not be up-to-date. Try rescanning this machine.'
End As Comment
From tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysOS On tsysOS.OScode = tblAssets.OScode
Inner Join TsysLastscan On tblAssets.AssetID = TsysLastscan.AssetID
Inner Join TsysWaittime On TsysWaittime.CFGCode = TsysLastscan.CFGcode
Left Join (Select Top 1000000 tblRegistry.AssetID,
tblRegistry.Regkey,
tblRegistry.Valuename,
tblRegistry.Value,
tblRegistry.Lastchanged
From tblRegistry
Where tblRegistry.Regkey Like '%SOFTWARE\lansweeper' And
tblRegistry.Valuename = 'BatteryCapacity') SubQuery1 On
SubQuery1.AssetID = tblAssets.AssetID
Inner Join lansweeperdb.dbo.tblWarranty On tblAssets.AssetID =
tblWarranty.AssetId
Inner Join lansweeperdb.dbo.tblWarrantyDetails On tblWarranty.WarrantyId =
tblWarrantyDetails.WarrantyId
Where Case
When SubQuery1.Valuename Is Not Null And SubQuery1.Valuename <> ''
Then 'Yes'
Else 'No'
End = 'Yes' And tblAssetCustom.State = 1 And TsysWaittime.CFGname = 'registry'
Order By tblAssets.Domain,
tblAssets.AssetName


Was trying to do something like this but couldn't get the case requirements in the correct location, SQL I have no real experience with.

Case
When tblRegistry.Valuename < '30000' Then '#ffadad'
When tblRegistry.Valuename < '35000' Then '#fff1ad'
When tblRegistry.Valuename > '40000' Then '#d4f4be'
End As backgroundcolor,

We cannot deploy packages via Lansweeper, but use SCCM.
I created this Powershell Script, that adds the info to the registry.
I included remaining capacity in percent. We will run the script and update data every week.
** Note that the names may not match the above report** 

Esben_D
Lansweeper Employee
Lansweeper Employee
This should get you started: https://www.lansweeper.com/report/hardware-failure-audit/

It contains data for the following hardware:

  • Power supply
  • Thermal state
  • Battery
  • CPU
  • GPU driver
  • HDD SMART status
  • HDD volumes
  • Monitor
  • Infrared device
  • Keyboard
  • Parallel port
  • PCMCIA controller
  • Printer
  • Scsi controller
  • Serial port
  • Tape drive