Powershell – looking up HP warranty information – part 2

Earlier I published a post about retrieving warranty information for HP hardware. However, the end date that is returned by the script might not always be correct!

Let me explain…

What the script does is executing a SOAP request to a website. The outcome of that request is XML data and the script returns three specific parameters:

  • ActiveEntitlement (true or false)
  • OverallEntitlementStartDate
  • OverallEntitlementEndDate

So let’s look at the outcome for a random server:

Based on the returned information warranty ends on 31-08-2017. But is that true? If I enter the same information on the HP support site I get the following data:

It looks like the powershell cmdlet returns the end date of the base warranty. But for this server a seperate support agreement is active and the actual warranty end date is 30-09-2019. So let’s see if this info is available is the returned XML data…

It is! The parameter OverallContractEndDate has the correct warranty end date. Returning this extra info is very easy. Just add one single line of code to the powershell script Get-HPEntWarrantyEntitlement.ps1. Default location is C:\Program Files\WindowsPowerShell\Modules\HPWarranty\2.6.2\Public.

Change this:

[HashTable]$output = @{
'SerialNumber' = $SerialNumber
'ProductNumber' = $ProductNumber
'ActiveEntitlement' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.ActiveWarrantyEntitlement
'OverallEntitlementStartDate' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.OverallWarrantyStartDate
'OverallEntitlementEndDate' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.OverallWarrantyEndDate
}

To this:

[HashTable]$output = @{
'SerialNumber' = $SerialNumber
'ProductNumber' = $ProductNumber
'ActiveEntitlement' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.ActiveWarrantyEntitlement
'OverallEntitlementStartDate' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.OverallWarrantyStartDate
'OverallEntitlementEndDate' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.OverallWarrantyEndDate
'OverallContractEndDate' = $entitlement.'ISEE-GetOOSEntitlementInfoResponse'.Data.EsReply.CombinedUnitEntitlement.OverallContractEndDate
}

Powershell – looking up HP warranty information

Today I wanted to get an overview of the warranty information of our ESX hosts. All the hosts are added to a HP Insight Remote Support server so the warranty information is available. However, using this information from powershell is a bit more challenging.

Fortunately I found a powershell module named HPWarranty. Could this be the solution?

First, install the PowerShellGet module. Details about the installation can be found here. Personally, I installed the MSI installer.

Second, start a new Powershell session and type Install-Module -Name HPWarranty. You will get a warning to install the NuGet provider 2.8.5.201. Select Yes. The installation will pull some files from an untrusted repository so you will get a second warning about that. I selected Yes. The module is now installed.

To try it out I entered the following command:
Get-HPEntWarrantyEntitlement -ProductNumber 654081-B21 -SerialNumber CZ3434BB9K

For some reason it asked me for credentials but after escaping out I got this output:

So the next question might be: how can I retrieve the product number and serial number? For this I wrote a powershell function that utilizes anonymous access to iLO:

Function Get-HPWarrantyInfo {

<# .SYNOPSIS Get HP warranty information from server .DESCRIPTION Use this script if you need to get warranty information .PARAMETER ComputerName Remote server name .EXAMPLE .\Get-HPWarrantyInfo.ps1 -ComputerName server1 Get the warranty information of the server server1 .NOTES Script name: Get-HPWarrantyInfo.ps1 Author: Jeroen Buren DateCreated: 08-05-2017 #>

[CmdletBinding(SupportsShouldProcess=$true)]

param(
    [parameter(ValueFromPipeLine=$True,ValueFromPipeLineByPropertyName=$True)]
    [string[]]$ComputerName = $env:COMPUTERNAME
)

Begin {
    $ErrorActionPreference = 'SilentlyContinue'
    $ComputerCount = $ComputerName.Count
}

Process {
    $outputobject = @()
    Foreach ($Computer in $ComputerName) {
        $ProgressCount++
        Write-Progress -Activity "Getting warranty information..." -Id 1 -Status "$($ProgressCount) / $($ComputerCount)" -CurrentOperation "$Computer" -PercentComplete (($ProgressCount / $ComputerCount) * 100)
        If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
            $XML = New-Object XML
            #Retrieving iLO hardware information
            $XML.Load("http://$Computer/xmldata?item=All")
            If ($?) {
                $object = New-Object PSObject -Property @{
                    Computername = $Computer
                    SerialNumber = $($XML.RIMP.HSI.SBSN)
                    ProductName = $($XML.RIMP.HSI.SPN)
                    SKU = $($XML.RIMP.HSI.PRODUCTID) -replace " ",""
                    WarrantyEndDate = $(Get-HPEntWarrantyEntitlement -ProductNumber $($XML.RIMP.HSI.PRODUCTID) -SerialNumber $($XML.RIMP.HSI.SBSN)).OverallEntitlementEndDate
                }
                $outputobject += $object
            }
        }
    }
    $outputobject.pstypenames.insert(0,'Hardware.Info')
    $outputobject | ft
}
}

The script is inspired from this page.