Gather HP server disk information using PowerShell

Gather HP server disk information using PowerShell

I frequently find a need to quickly gather information about the hard drives in my HP Proliant servers. Sometimes I just need to find the model numbers but sometimes I also need information such as serial numbers and firmware versions.
This information is useful when HP releases an urgent firmware upgrade advisory or launches a disk replacement program of which both seem to be quite common lately.

All the needed information is available through WMI on servers that have the HP Insight Management WBEM Providers installed.

Namespace: root\hpq
Classes: HPSA_DiskDrive and it’s associated classes

I wrote the following Powershell function that creates a command that gathers information from servers and returns them as an object that can be sorted, filtered and exported the way you need just as any powershell object.

Update: Improved cmdlets available here

function Get-HPArrayDisks
  Retrieves physical hard disk information for HP servers.
  The Get-HPArrayDisks function works through WMI and requires
  that the HP Insight Management WBEM Providers are installed on
  the server that is being quiered.
  .PARAMETER Computername
  The HP server for which the disks should be listed.
  This parameter is optional and if the parameter isn't specified
  the command defaults to local machine.
  First positional parameter.

  Lists physical disk information for the local machine

  Get-HPArrayDisks SRV-HP-A
  Lists physical disk information for server SRV-HP-A

  "SRV-HP-A", "SRV-HP-B", "SRV-HP-C" | Get-HPArrayDisks
  Lists physical disk information for three servers
  [Parameter(Mandatory=$false, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position = 1)][string]$Computername=$env:computername


    if ($pscmdlet.ShouldProcess("List disks on server " +$Computername)){
      $diskdrives =  Get-WmiObject -Computername $ComputerName -Namespace root\hpq -Query "select * from HPSA_DiskDrive"
      ForEach ($disk in $diskdrives){
        $OutObject = New-Object System.Object
        $OutObject | Add-Member -type NoteProperty -name ComputerName -value $ComputerName
        $OutObject | Add-Member -type NoteProperty -name Slot -value $disk.ElementName
        $OutObject | Add-Member -type NoteProperty -name Interface -value $disk.Description
        $OutObject | Add-Member -type NoteProperty -name RotationalSpeed -value $disk.DriveRotationalSpeed

        $drivePhys = Get-WmiObject -Computername $ComputerName -Namespace root\hpq -Query ("ASSOCIATORS OF {HPSA_DiskDrive.CreationClassName='HPSA_DiskDrive',DeviceID='" + $disk.DeviceID + "',SystemCreationClassName='" + $disk.SystemCreationClassName + "',SystemName='" + $disk.SystemName + "'} WHERE AssocClass=HPSA_DiskPhysicalPackageDiskDrive")
        $OutObject | Add-Member -type NoteProperty -name Model -value $drivePhys.Model
        $OutObject | Add-Member -type NoteProperty -name SerialNumber -value $drivePhys.SerialNumber.trim()

        $driveFW = Get-WmiObject -Computername $ComputerName -Namespace root\hpq -Query ("ASSOCIATORS OF {HPSA_DiskDrive.CreationClassName='HPSA_DiskDrive',DeviceID='" + $disk.DeviceID + "',SystemCreationClassName='" + $disk.SystemCreationClassName + "',SystemName='" + $disk.SystemName + "'} WHERE AssocClass=HPSA_DiskDriveDiskDriveFirmware")
        $OutObject | Add-Member -type NoteProperty -name FirmwareVersion -value $driveFW.VersionString.trim()

        $driveStorage = Get-WmiObject -Computername $ComputerName -Namespace root\hpq -Query ("ASSOCIATORS OF {HPSA_DiskDrive.CreationClassName='HPSA_DiskDrive',DeviceID='" + $disk.DeviceID + "',SystemCreationClassName='" + $disk.SystemCreationClassName + "',SystemName='" + $disk.SystemName + "'} WHERE AssocClass=HPSA_DiskDriveStorageExtent")
        $OutObject | Add-Member -type NoteProperty -name SizeInGigabytes -value ([math]::round(($driveStorage.BlockSize * $driveStorage.NumberOfBlocks) / 1000000000))
        $OutObject | Add-Member -type NoteProperty -name PowerOnHours -value $driveStorage.TotalPowerOnHours

        Write-Output $OutObject

Download hpdisks.ps1 and import it in your powershell session using the command

Import-Module hpdisks.ps1

When you have imported the module you can get help about it’s command just like you would with any other powershell command.

Get-Help Get-HPArrayDisks -detailed

Whatever you pipe into the Get-HPArrayDisks command will be treated as a server name and it will attempt to gather HP disk information from the server.
You can pipe names from the commnd line, from other commands or from text files using the Get-Contents command. Some quick examples:

Get-HPArrayDisks myservername

"myserver1","myserver2" | Get-HPArrayDisks | ft computername, slot, model, serialnumber

Get-Content allmyservers.txt | Sort-Object | Get-HPArrayDisks | Export-Csv -path myserverdisks.csv -NoTypeInformation

You may also want to read
Gather HP iLO information using PowerShell


10 thoughts on “Gather HP server disk information using PowerShell

  1. Thanks got it working as a function in my Inventory script no need to find way to see which drives are in which raid set

  2. Great information, I am wondering if you managed to find a way to get the spare part number for the hard disk drive from wmi? I can get this for the power supply and memory but not the hard drive.

    1. No I haven’t seen the spare part numbers of the disks anywhere. They don’t report them through the ACU utilities either so I assume they just don’t exist in WMI or anywhere else.

  3. Hello.. I am getting below error after import module.. Appreciate if someone could help me to resolve this. Thanks

    Import-Module : The specified module ‘hpdisks.ps1’ was not loaded because no
    valid module file was found in any module directory.
    At line:1 char:1
    + Import-Module hpdisks.ps1
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (hpdisks.ps1:String) [Impor
    t-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s