HP used to have their API which made it possible to gather the warranty information for bulk systems. Without that, it’s a tedious job entering the serial number of each device one by one into their warranty website. With the help of PowerShell, we can automate that process. I have written the script below to help with gathering the warranty start and end date based on the serial number of the system.
Before you get started, you’ll need Selenium. Read the article here if you need to set it up.
You’ll need to make sure you have a “temp” folder in your “C” drive and put your CSV file of serial numbers in that directory. The script will look there to pull in the serial number to use and search for each serial number one at a time. The header title in the CSV needs to be labeled “SerialNumber”.
Here’s the code. WARNING you may be seen as a bot and get blocked from HP’s website. Use at your own risk. The best approach would be to use a rotating VPN of some sort to change your request location.
Please let me know if the comment section below if it worked for you.
## Parse Web for Application Version
##
## Check Single serial at a time
##################################
## Selenium Check
##################################
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -force -Scope CurrentUser
if(-Not((Get-Module).name -match 'selenium')){
Install-Module -name selenium -Scope CurrentUser -AllowClobber -force
Import-Module -Name selenium
}
$dateTime = get-date -format MMddyyyyhhmmss
##################################
## Load Chrome Browser
##################################
$driver = Start-SeChrome -StartURL "https://support.hp.com/us-en/checkwarranty"
##################################
## Import HP Serial Number CSV
##################################
$HPSerialNumbers = Import-Csv -path C:\temp\HPG5.csv
##################################
## Clear and Create Array
##################################
$exportData = $null
$exportData = @()
##################################
## Total Count
##################################
$totalCount = ($hpSerialNumbers).count
$recordNumber = 0
##################################
## Loop through each Serial Number
##################################
foreach($HPSerialNumber in $HPSerialNumbers){
## Track Count
$recordNumber++
Write-host "Working on" $recordNumber "of" $totalCount -ForegroundColor Blue
## Clear Variables
$serialNumber = $endDate = $startDate = $null
## Set Variable
$serialNumber = ($HPSerialNumber.SerialNumber).trim()
Write-Host "Working on serial number" $serialNumber -ForegroundColor Green
## Set URL
$applicationURL = 'https://support.hp.com/us-en/checkwarranty'
Enter-SeUrl -driver $driver -Url $applicationURL
## Enter Serial Number in field
$serialField = $driver.FindElementsByTagName('input') | Where-Object {$_.GetAttribute('formcontrolname') -like "serialNumber"}
Send-SeKeys -Element $serialField -Keys $serialNumber
Start-Sleep -Seconds 1
## Submit Search
$submitButton = $driver.FindElementById('FindMyProduct')
$submitButton.click()
## Wait for page load before continuing
do {
write-host "Waiting for page to load" -ForegroundColor red
Start-Sleep -Seconds 1
} while (
$driver.PageSource -match "Coverage details"
)
## Warranty Start Date
$startDate = (($driver.FindElementsByClassName('startDatecontainer')).FindElementsByTagName('div') | Select-Object -last 1).text
Write-host "Warranty Start Date" $startDate -ForegroundColor Green
## Warranty End Date
$endDate = (($driver.FindElementsByClassName('endDatecontainer')).FindElementsByTagName('div') | Select-Object -last 1).text
Write-host "Warranty End Date" $endDate -ForegroundColor Green
Write-host " "
## Export Result Data to CSV
$exportData = [pscustomobject]@{
'SerialNumber' = $serialNumber;
'WarrantyStartDate' = $startDate;
'WarrantyEndDate' = $endDate
} | Export-Csv -path c:\temp\HP-Warranty-End-$dateTime.csv -Append
}## End Foreach Loop
##################################
## Exit Browser
##################################
$driver.close()
$driver.quit()
Get the latest from my blog when you sign up. Special offers are only offered to those who sign up. Specific DIY are emailed to users when they become available. Sign up today to get notified.
Hi,
I’m glad i discovered your page as i’m looking for an automated solution to get HP warranty. The script gives me some errors and do not know what to do with them… Hope you can help?
You cannot call a method on a null-valued expression.
At line:47 char:5
+ $serialNumber = ($HPSerialNumber.SerialNumber).trim()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Send-SeKeys : Cannot bind argument to parameter ‘Keys’ because it is an empty string.
At line:54 char:45
+ Send-SeKeys -Element $serialField -Keys $serialNumber
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Send-SeKeys], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Send-SeKeys
Method invocation failed because [System.Collections.ObjectModel.ReadOnlyCollection`1[[OpenQA.Selenium.IWebElement, WebDriver, Version=3.141.0.0, Culture=neutral, PublicKeyToken=null]]] does not conta
in a method named ‘FindElementsByTagName’.
At line:68 char:5
+ $startDate = (($driver.FindElementsByClassName(‘startDatecontaine …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Make sure your csv file has the column header title “serialnumber”. Try that and see what it does.