Share via


WMI and HP Product IDs

An HP Product ID is related to the hardware SKU

The plain-English way of getting the SKU is

Get-WMIObject –ComputerName $computerName Win32_ComputerSystem

However, our inventory system uses the HP product ID property stuffed in ILO.  As someone who uses the test lab, this isn’t something that I need to know, but one of the lab admins asked me if there was a way to pull the data.  Because he’s on the team that builds out the hardware on which I throw the test bits, it’s a good idea to stay on his good side.  After a bit of looking, I find it’s

(Get-WmiObject –ComputerName $ComputerName -Namespace 'Root\HPQ' HP_ComputerSystemChassis).ProductID

Of course, given that I was trying to give a coworker a solution, I added some framing logic:

 function Get-HpProductId
{
    param (
        [parameter(ValueFromPipeline=$true)][string[]]$ComputerName = @($env:Computername)
    );

    begin 
    {
        $ping = New-Object System.Net.NetworkInformation.Ping;
        $problems = @();
    }

    process
    {
        try
        {
            foreach ($_computerName in $ComputerName)
            {
                if (($ping.Send($_computerName, 1000)).Status -eq 'Success')
                {
                    Get-WmiObject -ComputerName $_computerName -Namespace 'Root\HPQ' -Query 'SELECT ProductID, SerialNumber, __Server from HP_ComputerSystemChassis' -ErrorAction SilentlyContinue |
                    Select-Object @{
                        n = 'ComputerName';
                        e = { $_.__Server; }
                    }, SerialNumber, ProductID
                }
                else
                {
                    $problems += $_computerName;
                }
            }
        }
        catch
        {
            Write-Warning "$($MyInvocation.MyCommand.Name) -ComputerName $_computerName returns '$($_.Exception.Message)'";
            $problems += $_computerName;
        }
    }

    end
    {
        $problems |
        ?{ $_; } |
        Sort-Object |
        Group-Object |
        % {
            Write-Warning "$($MyInvocation.MyCommand.Name) failed to ping `t$($_.Name)";
        }
    }
}