Closed jared-unify closed 7 months ago
Looks like the API endpoint it's trying to hit is dead.
Copying this from my other comment in case it helps. The Lenovo API is broken, you have to replace that script.
This was written by Rob Eberhardt in the comments on Kevin's Cyberdrain post. After you install the PSWarranty module, find where your PowerShell modules are installed and replace Powershell\Modules\PSWarranty\1.8.0\private\Get-LenovoWarranty.ps1 with the code below to scrape the warranty object from the Lenovo warranty webpage.
function get-LenovoWarranty([Parameter(Mandatory = $true)]$SourceDevice, $client) {
$today = Get-Date -Format yyyy-MM-dd
$APIURL = "https://pcsupport.lenovo.com/us/en/api/v4/mse/getproducts?productId=$SourceDevice"
$Req = Invoke-RestMethod -Uri $APIURL -Method get
if($req.id){
$APIURL = "https://pcsupport.lenovo.com/us/en/products/$($req.id)/warranty"
$Req = Invoke-RestMethod -Uri $APIURL -Method get
$search = $Req |Select-String -Pattern "var ds_warranties = window.ds_warranties \|\| (.*);[\r\n]*"
$jsonWarranties = $search.matches.groups[1].value |ConvertFrom-Json
}
if ($jsonWarranties.BaseWarranties) {
$warfirst = $jsonWarranties.BaseWarranties |sort-object -property [DateTime]End |select-object -first 1
$warlatest = $jsonWarranties.BaseWarranties |sort-object -property [DateTime]End |select-object -last 1
$WarObj = [PSCustomObject]@{
'Serial' = $jsonWarranties.Serial
'Warranty Product name' = $jsonWarranties.ProductName
'StartDate' = [DateTime]($warfirst.Start)
'EndDate' = [DateTime]($warlatest.End)
'Warranty Status' = $warlatest.StatusV2
'Client' = $Client
'Product Image' = $jsonWarranties.ProductImage
'Warranty URL' = $jsonWarranties.WarrantyUpgradeURLInfo.WarrantyURL
}
}
else {
$WarObj = [PSCustomObject]@{
'Serial' = $SourceDevice
'Warranty Product name' = 'Could not get warranty information'
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $Client
'Product Image' = ""
'Warranty URL' = ""
}
}
return $WarObj
}
That works great. Has anyone thought about creating a pull request for that?
When I'm checking warranties now, I seem to get an issue checking Lenovo warranties. Here's an example:
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send. At C:\Program Files\WindowsPowerShell\Modules\PSWarranty\1.6.0\private\Get-LenovoWarranty.ps1:4 char:12
The URL mentioned in the GET request seems to be not responding.