HP offers very easy solution ... Just install HP Battery Check - part of HP Support Assistant bloatware suite, run HP Battery Check Utility and wait for pretty program output page to get the results including the serial number and error code - information that you need to file the replacement claim.
Say this to any field tech and you will have to run - fast!
To avoid this or our customer I have prepared solution which automatically install just silently install the HP Battery Check Utility, silently run it and save results in Access DB on a server. Following description is for Windows 7 x86, but you can easily modify it for Window 8 and/or x64 architecture.
Access DB connection and DB update functions are snippets from Hey Scripting Guy article.
Deploy HP Battery Check
Latest version is a bit hard to find so here is the link to HP Battery Check version 4.3.2.2
- Unpack and create SCCM Package with installation program command line: setup.exe /S /v/qn
- Advertise/Deploy to SCCM Collection with your laptops
- So that was the easy part and you can reuse this package to install the utility beforehand during imaging process.
Run HP Battery Check and collect the result
Official Battery check information - Battery Check FAQ Page
I contacted the HP level 2 support and officially there are no silent switches for running the utility (BUT there is a silent switch /S). And it took another three calls to find out where the battery scan result file is stored.
To start the battery silently from PowerShell
Start-Process "${env:ProgramFiles(x86)}\Hewlett-Packard\HP Support Framework\Resources\hpbc.exe /S"
The above line will produce out BCResOut.xml file in ProgramData folder:
%ProgramData%\Hewlett-Packard\HP Support Framework\Resources\Logs\BCResOut.xml
That can be opened by PowerShell:
[xml]$battery = get-content $env:ProgramData"Hewlett-Packard\HP Support Framework\Resources\Logs\BCResOut.xml"
and extract the right information - that took a little bit of experimenting
Then we will need a function to connect to Access database:
Function Connect-Database($fl, $Tables)
{
$OpenStatic = 3
$LockOptimistic = 3
$connection = New-Object -ComObject ADODB.Connection
$connection.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=$Db" )
Update-Records($Tables)
} #End Connect-DataBase
The whole script is here:
<#
Name: Battery Check Script
Purpose: Silently run HP Battery Check and save results in Access file on the Server
Version: 1.1 - May, 2013
This script is provided "AS IS" with no warranties, confers no rights and
is not supported by the authors or deployment4everyone.
Author - Milos Pec
Blog : http://deployment4everyone.blogspot.com
Code Snipets from: http://technet.microsoft.com/en-us/magazine/2009.05.scriptingguys.aspx
#>
##########################################################
#Change this to your Access DB file on the server
$Db = "\\yourserver\deploy\batterycheck\BatteryCheck.mdb"
##########################################################
Function Check-Path($fl)
{
If(!(Test-Path -path (Split-Path -path $fl -parent)))
{
Throw "$(Split-Path -path $fl -parent) Does not Exist"
exit
}
ELSE
{
If(!(Test-Path -Path $fl))
{
Throw "$fl does not exist"
exit
}
}
} #End Check-Path
Function Connect-Database($fl, $Tables)
{
$OpenStatic = 3
$LockOptimistic = 3
$connection = New-Object -ComObject ADODB.Connection
$connection.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=$Db" )
Update-Records($Tables)
} #End Connect-DataBase
Function Update-Records($Tables)
{
$RecordSet = new-object -ComObject ADODB.Recordset
ForEach($Table in $Tables)
{
$Query = "Select * from $Table"
$RecordSet.Open($Query, $Connection, $OpenStatic, $LockOptimistic)
Invoke-Expression "Update-$Table"
$RecordSet.Close()
}
$connection.Close()
} #End Update-Records
Function Update-BatteryInfo
{
"Updating Battery Information"
$RecordSet.AddNew()
$RecordSet.Fields.Item("ComputerName") = $comp
$RecordSet.Fields.Item("Model") = $model
$RecordSet.Fields.Item("ComputerSerial") = $comp_serial
$RecordSet.Fields.Item("BatterySerialNumber") = $batt_serial
$RecordSet.Fields.Item("FailureID") = $failID
$RecordSet.Fields.Item("ResultCode") = $result_code
$RecordSet.Fields.Item("DesignCharge") = $design_charge
$RecordSet.Fields.Item("MaxCharge") = $max_charge
$RecordSet.Fields.Item("ChargeCapacity") = $charge_capacity
$RecordSet.Fields.Item("DateRun") = $run_date
$RecordSet.Update()
} #End Update-BatteryInfo
# Checking If Log File Exists
if (Test-Path "$env:ProgramData\Hewlett-Packard\HP Support Framework\Resources\Logs\BCResOut.xml") {
[xml]$battery = get-content $env:ProgramData"Hewlett-Packard\HP Support Framework\Resources\Logs\BCResOut.xml"
} else {
Throw "File not found ..."
}
#Execute Battery Scan
Check-Path -fl "${env:ProgramFiles(x86)}\Hewlett-Packard\HP Support Framework\Resources\hpbc.exe"
Start-Process "${env:ProgramFiles(x86)}\Hewlett-Packard\HP Support Framework\Resources\hpbc.exe /S" -Wait
# Script Start
$comp = $env:COMPUTERNAME
$model = $battery.BatteryTest.ComputerProductName
$comp_serial = $battery.BatteryTest.ComputerSerialNumber
$design_charge = $battery.BatteryTest.result[0].p[0].InnerText
$max_charge = $battery.BatteryTest.result[0].p[1].InnerText
$batt_serial = $battery.BatteryTest.result[0].p[14].InnerText
$failID = $battery.BatteryTest.result[0].FailureID
$charge_capacity = $battery.BatteryTest.result[0].v[9].InnerText
$run_date = $battery.BatteryTest.result[0].r[0].InnerText
$result_code = $battery.BatteryTest.result[0].ResultCode
# If uncommented following will create CVS file on your desktop - to test results
#Start Creating New file
#$batt_status = $Env:USERPROFILE + "\Desktop\" + $failID + "." + $env:COMPUTERNAME + "." +(Get-Date -uFormat "%Y%m%d-%H%M") + ".csv"
#"ComputerName,Model,ComputerSerialNumber,BatterySerialNumber,FailureID,ResultCode,DesignCharge,MaxCharge,Charge_Capacity,Date" | Out-File -FilePath $batt_status -Encoding Ascii
#Add-Content -Encoding Ascii $batt_status ($comp + "," + $model + "," + $comp_serial + "," + $batt_serial + "," + $failID + "," + $result_code + "," + $design_charge + "," + $max_charge + "," + $charge_capacity + "," + $run_date).ToString()
#End Creating New file
if($env:PROCESSOR_ARCHITECTURE -eq 'x86')
{
$Tables = "BatteryInfo"
Check-Path -fl $Db
Connect-DataBase -fl $Db -tables $Tables
}
#End Updating Access DB
Download the script BatteryCheck.ps1
Download the database template BatteryCheck.mdb
No comments:
Post a Comment