‎08-18-2021 02:01 AM
‎04-19-2022
08:17 AM
- last edited on
‎08-01-2022
12:31 PM
by
beacampos
Hi @CyberCitizen,
I have same requirement to check battery capacity due power continues interruption. Can you guide me how to save above script.
‎04-19-2022 08:21 AM
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.
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
‎08-19-2021 09:21 AM
‎08-23-2021 04:45 AM
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![]()
‎08-19-2021 01:25 AM
<?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% & Powershell Get-WmiObject -Namespace 'root\wmi' -Query 'select DesignedCapacity from BatteryStaticData' > battery.txt & if %errorlevel%==0 (findstr /l /b " DesignedCapacity " battery.txt > id.txt & for /f "tokens=2 delims=: " %a in (id.txt) do (reg add HKLM\Software\Lansweeper /v BatteryDesignedCapacity /t REG_SZ /d %a /f)) & del /f id.txt & 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% & Powershell Get-WmiObject -Namespace 'root\wmi' -Query 'select FullChargedCapacity from BatteryFullChargedCapacity' > battery.txt & if %errorlevel%==0 (findstr /l /b " FullChargedCapacity " battery.txt > id.txt & for /f "tokens=2 delims=: " %a in (id.txt) do (reg add HKLM\Software\Lansweeper /v BatteryCapacity /t REG_SZ /d %a /f)) & del /f id.txt & del /f battery.txt</Command>
<EditMode>False</EditMode>
<Conditions />
</Step>
</Steps>
<SoftwareVersion>8.4.100.9</SoftwareVersion>
</Package>
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
Case
When tblRegistry.Valuename < '30000' Then '#ffadad'
When tblRegistry.Valuename < '35000' Then '#fff1ad'
When tblRegistry.Valuename > '40000' Then '#d4f4be'
End As backgroundcolor,
‎07-26-2022 11:14 AM - edited ‎07-26-2022 11:29 AM
‎08-18-2021 12:21 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now