Extracting platform to softpaq mapping from security bulletins

In a previous post, we presented an approach for checking whether a given platform has a softpaq available that is mentioned in a given security bulletin.

To be clear, scripts shown in this blog are meant to illustrate concepts, and are not supported for production use by HP. Please feel free to use the concepts to create your own scripts, and always test your scripts on representative systems before going into production.

Here's an alternative, if you'd rather pull the entire list of softpaqs and platforms, and do your own processing.

The script

This time we'll start with the full script. The first half of the script is more or less the same as discussed in the previous blog post (minus the extra platform parameter), so we won't rehash that discussion. Check out the previous blog entry if you are not clear.

    [Parameter(position=0, Mandatory=$true)]

$url = "https://support.hp.com/us-en/document/$bulletin"
$regex = 'https?:\/\/ftp\.hp\.com\/pub\/softpaq\/sp[0-9]{3,8}-[0-9]{3,8}\/sp([0-9]{3,8})\.exe'

$page = Invoke-WebRequest -UseBasicParsing -Uri $url
$paqs = $page.Links  | where { $_.href  -and $_.href.toLower() -Match  $regex }   `
    |  select @{ Name = 'obj';   Expression={([regex]::match($_.href.toLower(), $regex)).`
        Groups[1].Value} }

$candidates = $paqs.obj | select -Unique
$results = [System.Collections.ArrayList]@()

$candidates | foreach {
    $__ = $_
    try  {
        $md = Get-SoftpaqMetadata  -number $_
    catch {
            Write-Warning "$__ is missing from the server, will not be included in result."

    $md."System Information".Keys|  where {$_ -Like "Sysid*"} | foreach {
        $num =  "SysName$($_.ToLower().trim('Sysid'))"
        $item = New-Object psobject -Property  @{ name=$md.'System Information'[$num]; sysid=$md."System Information"[$_].ToUpper().Replace('0X',""); softpaq=$__ }
    } | out-null

$results | sort -Property name

How it works

So what did we just do?

Instead of using Get-SoftpaqList, this time we retrieve the softpaq path, then retrieve that softpaq's metadata using the Get-SoftpaqMetadata function. This metadata contains various interesting information (softpaq name vendor, etc), but here we are interested in its list of supported platforms and system IDs.

Once we get the metadata for each softpaq mentioned in the bulletin, we do some work to create a table of softpaqs, system IDs, and system names, and we return that list to the caller.

Note: Using this approach, it is possible that this list will contain more platforms than mentioned in the bulletin, in cases where the softpaq mentioned covers multiple paltforms, but the bulletin addresses only a subset of those platforms.

Trying it out

If you run this script against the Zombieland bulletin for example, you should get a list similar to the following:

softpaq name                                                                                                                   sysid
------- ----                                                                                                                   -----
95654   HP 260 G2 DM,HP 260 G2 DM BUSINESS                                                                                     8184
95652   HP 260 G3                                                                                                              84F5
95654   HP 280 G2 MICROTOWER BUSINESS                                                                                          2B5E
95654   HP 280 G2 SMALL FORM FACTOR                                                                                            82C9
95654   HP 280 G2 SMALL FORM FACTOR                                                                                            8425
95652   HP 280 G3                                                                                                              8350
95652   HP 280 G3                                                                                                              0001
95652   HP 280 G3                                                                                                              834F
95683   HP 340 G4,HP 348 G4                                                                                                    852A
95683   HP 340 G4,HP 348 G4                                                                                                    82C8
95683   HP 340 G4,HP 348 G4                                                                                                    8529
95683   HP 340 G4,HP 348 G4                                                                                                    82C5
95683   HP 340 G4,HP 348 G4                                                                                                    82C3

Where to next

You can feed this result into your own scripts and use Get-Softpaq function to retrieve the softpaqs of interest (the first column in the output) for a given subset of platforms. We recommend that you do not attempt to match platforms by the product name, but rather by the product ID (the four digit hexadecimal string). It is possible that the same product name may map to multiple product IDs, or vice-versa, due to platform generation or configuration variations.

And that wraps today's edition of Fun with PowerShell, brought to you by HP. Hope you found this helpful. Keep in mind that these blog postings are not fully optimized for any particular purpose. Where a choice had to be made, we opted for for readability over performance.

Summary image credit Gnist Design, Tromsø, Norway, via pexels.com

Author : txvalp