Get Lenovo device warranty information with PowerShell
A client I've been working with needed a way to check the warranty status of thousands of Lenovo laptops they own. The end goal was to import the warranty expiration dates into Freshservice so they can estimate device lifecycles and find out which users needed laptop replacements.
Right now, Lenovo doesn't offer an API that could do this and I would need to look up each laptop one-by-one.
To solve this problem and avoid manual lookups, I wrote a short PowerShell script that takes the serial number, scrapes Lenovo's warranty check page and gets the warranty information for the device, then outputs to a PowerShell object with the regular and upgrade warranty statuses and the end dates.
In my use case, I exported all devices from Intune into a .csv file, filtered on all Lenovo devices, then ran the Get-LenovoWarrantyInformation script against all of them in a for
loop. I exported to a clean .csv file that I could then upload into the Freshservice inventory.
Here's the script:
# Get-LenovoWarrantyInformation.ps1
# Get Lenovo warranty information via web scrape using serial number.
# Example: Get-LenovoWarrantyInformation -SerialNumber 'BLAH'
# Tim D'Annecy 2024
function Get-LenovoWarrantyInformation {
param (
[Parameter(Mandatory = $true)]
[string]$SerialNumber
)
$Url = "https://csp.lenovo.com/ibapp/il/WarrantyStatus.jsp?serial=$($SerialNumber)"
$htmlContent = Invoke-WebRequest -Uri $Url -UseBasicParsing
$parsedHtml = $htmlContent.Content
$WarrantyStatus = [regex]::Match($parsedHtml, "Status: <\/b><span[^>]*><b>(.*?)<\/b>", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase).Groups[1].Value.Trim()
$WarrantyEndDate = [regex]::Match($parsedHtml, 'End Date: <\/b>(.*?)<\/td>', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase).Groups[1].Value.Trim()
$UpgradeWarrantyStatus = [regex]::Match($parsedHtml, "Upgrade Warranty Information.*?Status: <\/b><span[^>]*><b>(.*?)<\/b>", [System.Text.RegularExpressions.RegexOptions]::Singleline).Groups[1].Value.Trim()
$UpgradeWarrantyEndDate = [regex]::Match($parsedHtml, 'Upgrade Warranty Information.*?End Date: <\/b>(.*?)<\/td>', [System.Text.RegularExpressions.RegexOptions]::Singleline).Groups[1].Value.Trim()
$UpgradeWarrantyExcluding = [regex]::Match($parsedHtml, 'Upgrade Warranty Information.*?Excluding: <\/b>(.*?)<\/td>', [System.Text.RegularExpressions.RegexOptions]::Singleline).Groups[1].Value.Trim()
$WarrantyInfo = [PSCustomObject]@{
SerialNumber = $SerialNumber
WarrantyStatus = if ($WarrantyStatus) { $WarrantyStatus } else { 'N/A' }
WarrantyEndDate = if ($WarrantyEndDate) { $WarrantyEndDate } else { 'N/A' }
UpgradeWarrantyStatus = if ($UpgradeWarrantyStatus) { $UpgradeWarrantyStatus } else { 'N/A' }
UpgradeWarrantyEndDate = if ($UpgradeWarrantyEndDate) { $UpgradeWarrantyEndDate } else { 'N/A' }
UpgradeWarrantyExcluding = if ($UpgradeWarrantyExcluding) { $UpgradeWarrantyExcluding } else { 'N/A' }
}
return $WarrantyInfo
}
Also available on GitHub Gist:
There is no error catching or rate limiting for the script, so run at your own risk!
I hope this is helpful as a workaround, since Lenovo doesn't offer a proper API and this saved me a lot of time.