Server Management - Remote Server Management
1745918 Members
4500 Online
108723 Solutions
New Discussion

Re: iLO Powershell Write-Host Error Message

 
prisoner107
Occasional Collector

iLO Powershell Write-Host Error Message

I'm running the HP iLO cmdlets on a Task Schedule on Windows 2012 R2 Server. The script works great except I am tyring to find a way the Get-HPiLOHealthSummary cmdlet to output certain errors. Currently it only sends this part of the error: "System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression", if it detects that a server is offline.
What im looking to accomplish, is to only send me the iP Address Error info that outputs on the first line on the cmdlet via the email Body. It looks something like this: "Error - 10.10.5.2 - - retrieving information from iLO". That way if a server is offline (over 40 Servers in the array), I can quickly determine which server is offline with the IP address.

It looks like the HP iLO cmdlet is possibly using a Write-Host to output their error message and that may be the issue. Can somoene please assist. 

Get-Content C:\iLO.txt |
ForEach-Object {
$all = Get-HPiLOHealthSummary -Server $_ -Username User -Password Pass -DisableCertificateAuthentication 
foreach ($status in $all)
{
        New-Object psobject -Property @{
            Fans = $status.Fans.STATUS
            PSupply = $status.POWER_SUPPLIES.STATUS
            Temperature = $status.TEMPERATURE_STATUS
            Status = $status.STATUS_TYPE
            Drives = $status.STORAGE_STATUS
            BIOS = $status.BIOS_HARDWARE_STATUS
            Memory = $status.MEMORY_STATUS
            Network = $status.NETWORK_STATUS
            CPU = $status.PROCESSOR_STATUS
            IP = $status.IP
            Hostname = $status.HOSTNAME 
            
    } | Select-Object Hostname,IP,Fans,PSupply,Temperature,Status,Drives,BIOS,Memory,Network,CPU  | Export-Csv -Path C:\Scripts\ilo\ilo.csv -Append -NoTypeInformation
  }}
    
$body = $Error[1]|ConvertTo-Html |Out-String
$mailprops=@{
	Subject = 'ilo Status'
	Attachments = 'C:\ilo.csv'
	SmtpServer = 'MyServer'
	From = 'Ilo@hpilo'
	To='OurAdmins.com'
	BodyAsHtml=$true
}
Send-MailMessage @mailprops -Body $body
2 REPLIES 2
Leif_Maxfield
New Member

Re: iLO Powershell Write-Host Error Message

Not 100% sure I'm actually addressing your question, but you could maybe try using ErrorVariable, like this:

$all = Get-HPiLOHealthSummary -Server $_ -Username User -Password Pass -DisableCertificateAuthentication -ErrorAction SilentlyContinue -ErrorVariable iloErr

Then check to see if $iloErr is not $null, and check its contents.

I just ran into what appears to be a bug w/ the current version of the HP iLO cmdlets when using 'DisableCertificateAuthentication' that might result in spurious error messages in your error variable, however. This is actually how I found your thread (some of the error text is similar). So if you run into that, this was the issue at around line 4548 in HPiLOCmdlets.psm1. Had to wrap their try block in an if statement that tested for $null.

elseif($tempArrayForProcess[$i].parameterName -eq "Credential")
{
    $credential_index = $i
    # Changed this block to work around bug that possibly occurs
    # when "DisableCertificateAuthentication" is set.
    if (($tempArrayForProcess[$i] -ne $null) -and ($tempArrayForProcess[$i].parameterValue -ne $null)) {
        try{
            # Getting a "cannot call a method on a null-valued expression" on this line if 
            # we don't check for $null in the if statement above
            $typeCredential = $tempArrayForProcess[$i].parameterValue.GetType().Name
        }
        catch
        {
            $typeCredential = $null
            $global:error.RemoveAt($global:error.count-1)
        }
    }
}
prisoner107
Occasional Collector

Re: iLO Powershell Write-Host Error Message

Thank you for the reply. I was able to solve this issue by using this solution by Dave Wyatt. 

https://powershell.org/forums/topic/hp-ilo-cmdlets-violate-the-first-law-of-powershell/