vSphere IPMI Information

First of all thank you for visiting my new Blog. As my first post I wanted to do something useful (most things I think up while doodling are a bit silly for a first post).

A recent issue at work showed that there weren't any iLO addresses in vSphere. The IPMI/iLO settings in vSphere allow hosts to be powered on from the vsphere client either manually or automatically as part of DPM. With a few hundred hosts to manage I couldn't really stomach entering the information manually so cue the HPE iLO cmdlets!

For this script you will need:

  1. VMware PowerCLI 6 or higher (6.5r1 can be found here)
  2. HPE iLO cmdlets (v2.0 can be found here)

The first important thing to get out of the way is working with your naming convention. You'll need a solid host to iLO convention or it won't be all that easy to implement. In my case this is already a thing, for the most part, and it's a simple letter swap. Some customers I've worked at use the iLO-<hostname> convention too.

Next is the fun to be had with iLO cmdlets and certificates. You can disable the certificate authentication with a trigger now so it's not too much trouble. I intend on doing a post about auto-enrolling the iLO's for CA certificates soon.

Lastly is knowing about the unique way VMware like to make cmdlets. For reasons unknown to science, they don't expose all attributes from the Get- command like some and don't even allow you to ask for all attributes with a trigger (Active Directory cmdlets for example). To be completely different their extended object attributes and functions are found after performing a Get-View which is used below to expose the function to update IPMI information. It's good to play with Get-View to see what it can do for you as the options are often poorly documented but powerful.

On with the function:

#Modules
Import-Module vmware.vimautomation.core,HPEiLOcmdlets

#Connect to vsphere
Connect-VIServer '<your vcenter here>'

#credentials for connecting and vsphere (domain accounts work too <NETBIOS>\<username>)
$iLOUN = Read-Host -Prompt 'iLO Username:'
$iLOPW = Read-Host -AsSecureString -Prompt 'iLO Password:'

Function Update-IPMIInfo ($VMHostName)
   {$VMHost = Get-VMHost $VMHostName
    #Show what's already there if anything
    If ($VMhost.ExtensionData.Config.Ipmi -ne $Null) {Write-Host $VMhost.ExtensionData.Config.Ipmi.BmcIpAddress -ForegroundColor Magenta}

    #Do your own Naming convention thing here as mine probably wont work for you! Perhaps: ('ILO-' + $VMHost.Name)
    $iLOName = $VMhost.Name.Replace("s","r")

    #Grab the data from iLO
    $iLOConnection = Connect-HPEiLO -IP $iLOName -Credential (New-Object System.Management.Automation.PSCredential ($iLOUN,$iLOPW)) #-DisableCertificateAuthentication
    $iLONet = Get-HPEiLOIPv4NetworkSetting -Connection $iLOConnection
    
    #Create and fill in the IPMI data
    $IpmiInfo = New-Object Vmware.Vim.HostIpmiInfo
    $IpmiInfo.BmcIpAddress = $iLONet.IPv4Address
    $IpmiInfo.BmcMacAddress = $iLONet.MACAddress
    $IpmiInfo.Login = $iLOUN
    $IpmiInfo.Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($iLOPW))

    #Finally update the host
    $VMHostView = Get-View $VMHost
    $VMHostView.UpdateIpmi($IpmiInfo)

    #Refresh the variable and show the new IPMI data
    $VMHost = Get-VMHost $VMHost.Name
    $VMhost.ExtensionData.Config.Ipmi
   }

#Single example
Update-IPMIInfo '<hostname as it appears in vsphere>'

#Numbered hosts example (updates Host01,Host02 and Host03)
0..3 | % {Update-IPMIInfo ('Host' + ("{0:D2}" -f $_))}

#Whole of vSphere example
Get-VMHost | % {Update-IPMIInfo $_.Name}

 I hope this helps out some people or sparks ideas in others. I'd like to hear from you either way so please do comment below.

o7

Add comment

Loading