2

Get HP Server Status Using Powershell (iLO Query)

If you have a homelab (or work environment) filled with HP ProLiant equipment as I do, you might have found yourself checking your power consumption and temperatures on a regular basis to ensure they’re not overheating and/or drawing too much power. Since I run my homelab in a small, non-ventilated area I’ve found myself doing this on a regular basis. The problem is, I had to keep logging into the iLO (Integrated Lights Out) to check the settings and after a while I started wondering why I was manually logging every so often to check the same thing. Luckily for myself, I am pretty well versed in Powershell and created a script to check those settings for me. Hence the title, Get HP Server Status Using Powershell (iLO Query).

This script uses Invoke-WebRequest to initially login and parse the data needed, then it converts from JSON to output the data into a nice and neat table format. The best part is that you can query multiple servers at once.

Script Parameters

    -ComputerName

IPAddress was added as an alias to specify which servers you would like to query. Again, this is the ComputerName or IPAddress of the iLO IP.

    -Credential

The -Credential parameter was implemented so you can enter in your credentials for that added security. For those of you who don’t care and use it strictly for your homelab, I provided the option to hardcode your creds into the script.

    -Summary

The -Summary parameter gives you just that, a summary of your server and iLO settings. The output is shown below.


PS C:\> Get-HPServerStatistics -IPAddress 10.0.7.156 -Credential $Credential -Summary

ComputerName  : 10.0.7.156
ProductName   : ProLiant DL360p Gen8
IP_Address    : 10.0.7.156
iLO_Firmware  : 2.10 Jan 15 2015
License       : iLO 4 Advanced
iLO_Name      : PAC-SAN01-iLO.
System_Health : OP_STATUS_OK

 

Not specifying the -Summary parameter will result in a different output. Here’s what that’ll look like.


PS C:\> Get-HPServerStatistics -ComputerName 10.0.7.156 -Credential $Credential

ComputerName ProductName          CurrentPower CurrentTemp
------------ -----------          ------------ -----------
10.0.7.156   ProLiant DL360p Gen8 85 Watts      73.4F / 23C

Get HP Server Status Using Powershell

I tested this script on several HP models and several iLO versions. Unfortunately, I don’t have any machines with iLo 5 and above so I wasn’t able to test with that. However, I was able to test with iLO 3 and iLO 4 (Gen 7 and Gen 8) machines and those worked very well. In my testing, I found that iLO 2 did not work.

In order for the script to work, you must enter the IP of the iLO address. If you have any questions regarding the script, be sure to leave a comment down below and I’ll do my best to help you out.
 


Function Get-HPServerStatistics {
<#
.Synopsis
    This will grab current readings from an HP Proliant Server iLO settings.  Tested on HP Proliant DL580 G7, DL360 G8, DL380 G8, DL380 G7 with iLO versions 3.0 and 4.0
    For updated help and examples refer to -Online version.
 

.DESCRIPTION
    This will grab current readings from an HP Proliant Server iLO settings.  Tested on HP Proliant DL580 G7, DL360 G8, DL380 G8, DL380 G7 with iLO versions 3.0 and 4.0
    For updated help and examples refer to -Online version.


.NOTES   
    Name: Get-HPServerStatistics
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2019-Feb-15
    DateUpdated: 2019-Feb-15

.LINK
    https://thesysadminchannel.com/get-hp-server-status-using-powershell-ilo-query -


.EXAMPLE
    For updated help and examples refer to -Online version.

#>

    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            Position=0)]

        [Alias("IPAddress")]

        [string[]] $ComputerName,

        [switch]   $Summary,

        [System.Management.Automation.PSCredential]
        $Credential
    )


    BEGIN {
    #Used to ignore any SSL cert errors when connecting to HP iLO.
    #This should revert to the default Policy upon closing your Powershell window.
    add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

    }

    PROCESS {
        Foreach ($Computer in $ComputerName) {
            try {
                if ($Credential) {
                        #Inserting Username and password from Get-Credential
                        #$Credential = (Get-Credential)
                        $Username = $Credential.GetNetworkCredential().username
                        $Password = $Credential.GetNetworkCredential().password
                    } else {
                        #Hardcoding Username and Password in clear text. For cowboys only.
                        $Username = 'administrator'
                        $Password = 'Password'
                }

                $URL      = "https://$Computer/json"
                $Login = Invoke-WebRequest -Uri "$URL/login_session" -Method "POST" -Headers @{
                    "Cookie"="sessionLang=en; 
                    UserPref=fahrenheit%3Dtrue; 
                    sessionUrl=https%253A%2F%2F$Computer%2Findex.html"; 
                } -Body "{`"method`":`"login`",`"user_login`":`"$Username`",`"password`":`"$Password`"}" -SessionVariable 'Session'

                $Overview = Invoke-WebRequest -Uri "$URL/overview" -Headers @{
                    "Cookie"="sessionLang=en; 
                    UserPref=fahrenheit%3Dtrue; 
                    sessionUrl=https%253A%2F%2F$Computer%2Findex.html"; 
                } -WebSession $Session
                $Overview = $Overview.Content | ConvertFrom-Json

                $PowerReading = Invoke-WebRequest -Uri "$URL/power_readings" -Headers @{
                    "Cookie"="sessionLang=en; 
                    UserPref=fahrenheit%3Dtrue; 
                    sessionUrl=https%253A%2F%2F$Computer%2Findex.html"; 
                } -WebSession $Session
                $PowerReading = $PowerReading.Content | ConvertFrom-Json

                $Temperature = Invoke-WebRequest -Uri "$URL/health_temperature" -Headers @{
                    "Cookie"="sessionLang=en; 
                    UserPref=fahrenheit%3Dtrue; 
                    sessionUrl=https%253A%2F%2F$Computer%2Findex.html";
                } -WebSession $Session

                $TempReading = $Temperature.Content | ConvertFrom-Json  | select -ExpandProperty temperature
                $TempReading = $TempReading[0]

                if ($Overview.power -eq 'OFF') {
                        $TempReadingC = 0
                        $TempReadingF = 0
                    } else {
                        $TempReadingC = $TempReading.currentreading
                        $TempReadingF = ($TempReadingC * 9/5) + 32
                }
                

                if ($Summary) {
                        $Properties = @{ComputerName  = $Computer
                                        ProductName   = $Overview.product_name
                                        IP_Address    = $Overview.ip_address
                                        iLO_Firmware  = $Overview.ilo_fw_version
                                        License       = $Overview.license
                                        iLO_Name      = $Overview.ilo_name
                                        System_Health = $Overview.system_health  
                                      }
                        $Object = New-Object -TypeName PSCustomObject -Property $Properties | Select ComputerName, ProductName, IP_Address, iLO_Firmware, License, iLO_Name, System_Health

                    } else {
                        $Properties = @{ComputerName = $Computer
                                        ProductName  = $Overview.product_name
                                        CurrentPower = "$($PowerReading.present_power_reading) Watts"
                                        CurrentTemp  = "$($TempReadingF)F / $($TempReadingC)C"
                                      }
                    $Object = New-Object -TypeName PSCustomObject -Property $Properties | Select ComputerName, ProductName, CurrentPower, CurrentTemp
                }
            } catch {
                
                $ErrorMessage = $Computer + " Error: " + $_.Exception.Message

            } finally {
                Write-Output $ErrorMessage

                Write-Output $Object

                $Properties = $null
                $Object     = $null
                $Overview   = $null
                $ErrorMessage = $null
                
            }
        }
    }

    END {}

}

Save the above script to a file called Get-HPServerStatistics.ps1 and place it in your scripts folder. Since the script is a function, you will need to dot-source the function to be able to run it. To do that, type:

  • . C:\_Scripts\Get-HPServerStatistics.ps1

Get-HPServerStatistics

 

So after running this script on a few of my own servers it appears that I need to upgrade my firmware to a later version.. Jan 2015?? Geez. That’s a no bueno. Anyway, I hope some of you can find some use out of this script to easily get some info our of your HP servers.

That’s all there is for the Get HP Server Status Using Powershell (iLO Query) script. Don’t forget to check us out at theSysadminChannel on Youtube for more awesome video content.

5/5 - (14 votes)

Paul Contreras

Hi, my name is Paul and I am a Sysadmin who enjoys working on various technologies from Microsoft, VMWare, Cisco and many others. Join me as I document my trials and tribulations of the daily grind of System Administration.

2 Comments

  1. Dear SIr, Error: The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.

Leave a Reply

Your email address will not be published. Required fields are marked *