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 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 #>


    [string[]]$ComputerName = $env:COMPUTERNAME

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

Process {
    $outputobject = @()
    Foreach ($Computer in $ComputerName) {
        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
            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 | ft

The script is inspired from this page.

Restoring Task Sequences the easy way

A while ago I was asked if it was possible to restore a Task Sequence. My first reaction was “of course”. But digging into the problem I quickly realized I would need to restore the entire ConfigMgr database. And because it was a primary site under a CAS I was a bit reluctant. The immediate need for the restore went away but it made me think of a more easy way of restoring a Task Sequence. This is what I came up with.

The backup of the database is being done from within SQL Server with a maintenance plan. I already added a SQL Agent Job to this Maintenance Plan so what if I could add a second job to create an export of all the excisting Task Sequences?

The first step was to create the code to export all Task Sequences.

import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + ‘\ConfigurationManager.psd1’)
Set-Location CM0:
Foreach ($ts in Get-CMTaskSequence) {
    $ZipName = "\\server\share$\task-sequences\" + $ts.Name + ".zip"
    Export-CMTaskSequence -Name $ts.Name -ExportFilePath $ZipName

Then add this code as a Powershell script to a SQL Agent Job. Make sure that the service account that is running the SQL job has appropiate permissions in ConfigMgr.

To make it work I had to logon to the ConfigMgr console once with the SQL service account. This makes sure that all registry keys are there…

Now everytime that my SQL backup runs it also makes a zip file of every Task Sequence. Include the folder in your file level backup to add retention because the Export-CMTaskSequence cmdlet will overwrite existing zip files.

You could also use WMI Event Scripting to create a backup everytime a Task Sequence is changed… But that is something for the future.