Working with the HPQ WMI Provider to find NIC Information on HP Proliant Servers

I recently had a task to query NIC information on a number of HP Proliant servers, this included the connected NIC speed, duplex settings and status of the configured HP Team. I initally looked at the WMI class Win32_NetworkAdapterConfiguration  which contains a lot of info around NIC configuration. Unfortunately, it does not include NIC speed or duplex settings.

Looking for alternatives, I discovered a script from Hugo Peeters which instead queried the registry key HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318} which looked like it would do the job. However, for some reason this works fine for HP rackmount servers, but blades do not appear to publish NIC info to that registry key so I needed to look for something else.

A colleague pointed me to the HPQ WMI Provider, which I had not seen before and there does not appear to be a lot of published info about either. It can be installed as part of the HP Proliant installation process and adds 800+ classes that can be queried via WMI -  a sample is shown below from the Root\HPQ Namespace:

In this instance, I was able to use the following classes to obtain the information I needed:

HP_EthernetTeam HP_EthernetPort HP_WinEthLANEndpoint

There is an absolute wealth of information stored in here, so I would encourage you to check it out if you work with Windows Server on HP systems. The script I put together puts together a basic report of some key NIC info, with the knowledge that there are never more than 4 NICs in a server being queried.

Note that I have used the parameter -ErrorAction Stop in the WMI queries, to enforce a terminating error to be generated if the WMI query fails. Without this, the error is non-terminating and does not get caught by the Catch statement.


$HP\_EthernetTeam = Get-WmiObject -Namespace root\\hpq -Class HP\_EthernetTeam -ComputerName $ComputerName -ErrorAction Stop

``` ```

<# .SYNOPSIS Retrieve HP NIC Info from HPQ WMI Namespace

.DESCRIPTION Retrieve HP NIC Info from HPQ WMI Namespace

.PARAMETER  ServersInputFile Path to the file containing server names

.PARAMETER  OutputFile Path to the csv file to output data to

.EXAMPLE PS C:\\> Get-HPNICStatus.ps1 -ServersInputFile C:\\Scripts\\Servers.txt -OutputFile C:\\Scripts\\HPNICStatus.csv

#>

\[CmdletBinding()\] param(

\[Parameter(Position=0,Mandatory=$true,HelpMessage="Path to the file containing server names")\] \[System.String\] $ServersInputFile,

\[Parameter(Position=1,Mandatory=$true,HelpMessage="Path to the csv file to output data to")\] \[System.String\] $OutputFile )

$ComputerNames = Get-Content $ServersInputFile

\# Allow conversion to MB/sec for NIC speed $NICSpeedConversionConstant = 1000000

$myCol = @()

foreach ($ComputerName in $ComputerNames){

Write-Host "\`n\`n" Write-Host "Querying NIC info on $ComputerName"

\# Test for HPQ WMI Namespace and deal with a failure in catch statement try {

$HP\_EthernetTeam = Get-WmiObject -Namespace root\\hpq -Class HP\_EthernetTeam -ComputerName $ComputerName -ErrorAction Stop $HP\_EthernetPort = Get-WmiObject -Namespace root\\hpq -Class HP\_EthernetPort -ComputerName $ComputerName -ErrorAction Stop $HP\_WinEthLANEndpoint = Get-WmiObject -Namespace root\\hpq -Class HP\_WinEthLANEndpoint -ComputerName $ComputerName -ErrorAction Stop

Write-Host "Successful query on $ComputerName"

\# Calculate Team Health Status based on WMI query result switch ($HP\_WinEthLANEndpoint.HealthState) { "0" {$HPTeamStatus = "Unknown"; break} "5" {$HPTeamStatus = "OK"; break} "10" {$HPTeamStatus = "Degraded/Warning"; break} "15" {$HPTeamStatus = "Minor Failure"; break} "20" {$HPTeamStatus = "Major Failure"; break} "25" {$HPTeamStatus = "Critical Failure"; break} "30" {$HPTeamStatus = "Non-recoverable Error"; break} default {$HPTeamStatus = "Unknown"} }

\# Check Ethernet Port Status $EthernetPortHealthStateArray = @()

foreach ($EthernetPort in $HP\_EthernetPort){

switch ($EthernetPort.HealthState) { "0" {$EthernetPortHealthState = "Unknown"; break} "5" {$EthernetPortHealthState = "OK"; break} "10" {$EthernetPortHealthState = "Degraded/Warning"; break} "15" {$EthernetPortHealthState = "Minor Failure"; break} "20" {$EthernetPortHealthState = "Major Failure"; break} "25" {$EthernetPortHealthState = "Critical Failure"; break} "30" {$EthernetPortHealthState = "Non-recoverable Error"; break} default {$EthernetPortHealthState = "Unknown"} }

$EthernetPortHealthStateObject = "" | Select-Object EthernetPortName,EthernetPortHealthStatus $EthernetPortHealthStateObject.EthernetPortName = $EthernetPort.Description $EthernetPortHealthStateObject.EthernetPortHealthStatus = $EthernetPortHealthState $EthernetPortHealthStateArray += $EthernetPortHealthStateObject

}

$MYObject = “” | Select-Object Servername,HPTeamName,HPTeamStatus,HPTeamSpeed,NIC1Description,NIC1Model,NIC1Speed,NIC1FullDuplex,NIC1HealthState,NIC2Description,NIC2Model,NIC2Speed,NIC2FullDuplex,NIC2HealthState,NIC3Description,NIC3Model,NIC3Speed,NIC3FullDuplex,NIC3HealthState,NIC4Description,NIC4Model,NIC4Speed,NIC4FullDuplex,NIC4HealthState $MYObject.Servername = $ComputerName $MYObject.HPTeamName = $HP\_EthernetTeam.Description $MYObject.HPTeamStatus = $HPTeamStatus $MYObject.HPTeamSpeed = \[string\]($HP\_EthernetTeam.Speed / $NICSpeedConversionConstant) + " MB/sec" $MYObject.NIC1Description = $HP\_EthernetPort\[0\].Description $MYObject.NIC1Model = $HP\_EthernetPort\[0\].Caption $MYObject.NIC1Speed = \[string\]($HP\_EthernetPort\[0\].Speed / $NICSpeedConversionConstant) + " MB/sec" $MYObject.NIC1FullDuplex = $HP\_EthernetPort\[0\].FullDuplex $MYObject.NIC1HealthState = $EthernetPortHealthStateArray\[0\].EthernetPortHealthStatus $MYObject.NIC2Description = $HP\_EthernetPort\[1\].Description $MYObject.NIC2Model = $HP\_EthernetPort\[1\].Caption $MYObject.NIC2Speed = \[string\]($HP\_EthernetPort\[1\].Speed / $NICSpeedConversionConstant) + " MB/sec" $MYObject.NIC2FullDuplex = $HP\_EthernetPort\[1\].FullDuplex $MYObject.NIC2HealthState = $EthernetPortHealthStateArray\[1\].EthernetPortHealthStatus $MYObject.NIC3Description = $HP\_EthernetPort\[2\].Description $MYObject.NIC3Model = $HP\_EthernetPort\[2\].Caption $MYObject.NIC3Speed = if ($HP\_EthernetPort\[2\].Speed -ne $null){\[string\]($HP\_EthernetPort\[2\].Speed / $NICSpeedConversionConstant) + " MB/sec"} $MYObject.NIC3FullDuplex = $HP\_EthernetPort\[2\].FullDuplex $MYObject.NIC3HealthState = $EthernetPortHealthStateArray\[2\].EthernetPortHealthStatus $MYObject.NIC4Description = $HP\_EthernetPort\[3\].Description $MYObject.NIC4Model = $HP\_EthernetPort\[3\].Caption $MYObject.NIC4Speed = if ($HP\_EthernetPort\[3\].Speed -ne $null){\[string\]($HP\_EthernetPort\[3\].Speed / $NICSpeedConversionConstant) + " MB/sec"} $MYObject.NIC4FullDuplex = $HP\_EthernetPort\[3\].FullDuplex $MYObject.NIC4HealthState = $EthernetPortHealthStateArray\[3\].EthernetPortHealthStatus $myCol += $MYObject }

\# If WMI query fails catch {

Write-Host "Unsuccessful query on $ComputerName"

$MYObject = “” | Select-Object Servername,HPTeamName,HPTeamStatus,HPTeamSpeed,NIC1Description,NIC1Model,NIC1Speed,NIC1FullDuplex,NIC1HealthState,NIC2Description,NIC2Model,NIC2Speed,NIC2FullDuplex,NIC2HealthState,NIC3Description,NIC3Model,NIC3Speed,NIC3FullDuplex,NIC3HealthState,NIC4Description,NIC4Model,NIC4Speed,NIC4FullDuplex,NIC4HealthState $MYObject.Servername = $ComputerName $MYObject.HPTeamName = "HPQ WMI is not installed or WMI query failed" $MYObject.HPTeamStatus = "N/A" $MYObject.HPTeamSpeed = "N/A" $MYObject.NIC1Description = "N/A" $MYObject.NIC1Model = "N/A" $MYObject.NIC1Speed = "N/A" $MYObject.NIC1FullDuplex = "N/A" $MYObject.NIC1HealthState = "N/A" $MYObject.NIC2Description = "N/A" $MYObject.NIC2Model = "N/A" $MYObject.NIC2Speed = "N/A" $MYObject.NIC2FullDuplex = "N/A" $MYObject.NIC2HealthState = "N/A" $MYObject.NIC3Description = "N/A" $MYObject.NIC3Model = "N/A" $MYObject.NIC3Speed = "N/A" $MYObject.NIC3FullDuplex = "N/A" $MYObject.NIC3HealthState = "N/A" $MYObject.NIC4Description = "N/A" $MYObject.NIC4Model = "N/A" $MYObject.NIC4Speed = "N/A" $MYObject.NIC4FullDuplex = "N/A" $MYObject.NIC4HealthState = "N/A" $myCol += $MYObject }

Clear-Variable HP\_EthernetTeam,HP\_EthernetPort,HP\_WinEthLANEndpoint,HPTeamStatus,EthernetPortHealthStateArray,EthernetPortHealthStateObject,EthernetPortHealthStateArray

}

$myCol | Export-Csv $OutputFile -NoTypeInformation

sdf