iLO

Nice to Know – Getting Hardware info(iLO) data using native PowerShell (and no need for credentials)

During my daily work (building datacenters) I normally need to inventory server information and in many cases there is no infrastructure in place, things like OpsMgr, SCCM, SCVMM and HP’s native tools does not really exists (yet). But for me to be able to redeploy machines, patch machines and get some kind order out of the chaos I need to know.

First step – Getting the idea of it

In HP Servers there is something called iLO, for many people it is the life-line to logon to and do remote console and access, what many people does not know is that you can reach that information using a normal web browser, like this:

Just browse to http://IPaddress/xmldata?item?All and you will se this

image

Next Step – Reading the information using PowerShell and treat it as a PSObject

The basic ide here is to read from each and every IP, the first thing is to try to get the name from DNS, then we load the XML data, we then convert, modify, bend and twist so it looks the way I need it and last we dump it in a way we like to view it. In this case dumping means Out-Gridview, but it could easily be anything else. You could also add something that “sweeps” the network and try to read it as XML to get a “iLO Scanner”. There is a PowerShell toolkit that gives us a massive amount of CMDlets and they are nice, but, the all require some kind of authentication, this does not require anything at all :-)

image

(in textform)

$iLOIP = "192.168.133.15","192.168.133.16","192.168.133.133","192.168.133.142"

Function GetiLOData {
    foreach ($IP in $ILOIP){
    $XML = New-Object XML
    $HostName = Resolve-DnsName -Name $IP
    $XML.Load("http://$IP/xmldata?item=All")
    New-Object PSObject -Property @{
      iLOName = $($HostName.NameHost);
      iLOIP = $($IP);
      ServerType = $($XML.RIMP.HSI.SPN);
      ProductID = $($XML.RIMP.HSI.PRODUCTID);
      UUID = $($XML.RIMP.HSI.cUUID);
      Nic01 = $($XML.RIMP.HSI.NICS.NIC[0].MACADDR);
      Nic02 = $($XML.RIMP.HSI.NICS.NIC[1].MACADDR);
      ILOType = $($XML.RIMP.MP.PN);
      iLOFirmware = $($XML.RIMP.MP.FWRI)
    }
}
}

GetiLOData | Select iLOName,iLOIP,ServerType,ProductID,Nic01,Nic02,UUID,iLOType,iLOFirmware | Out-GridView

Next Step – Enjoy the view

image

You can download the PowerShell script here http://sdrv.ms/ITvFyO

/mike

Categories: iLO, PowerShell

Tagged as: , ,

8 replies »

  1. Hi Mike,

    Thank you for posting your script. I have been searching hi and low looking for a way to get HP iLO IP and MAC addresses but have not found anything that met my needs. Your script included.

    My problem was that I am working with older machines that use iLO and iLO 2. Also, on most of the machines, I did not know the IP address of the iLO to be able to run your script against it. What I needed was something that would work if I only had the server name (OS hostname). I finally managed to come up with something that worked for me and because it took me so long to complete this solution I thought that I would add it to your post in case it can save someone else out there some time.

    My solution assumes that the server OS has hponcfg.exe installed in its default location of C:\Program Files\HP\HPONCFG\.

    With this in mind, if you were to log on to the server and execute the command:

    C:\Program Files\HP\HPONCFG\hponcfg.exe /f C:\Program Files\HP\HPONCFG\GetNet.txt

    Where GetNet.txt is a simple text file located in the same directory as hponcfg.exe and containing the following lines of text:

    you will get a result similar to the following:

    C:\Program Files\HP\hponcfg>hponcfg.exe /f GetNet.txt
    Firmware Revision = 1.94 Device type = iLO Driver name = CpqCiDrv

    Script succeeded

    This information provides both the IP and the MAC address of the iLO. Now to write a Powershell script to utilize this process.

    # Create a drive mapping to the remote hponcfg folder and copy the GetNet.txt file to that folder
    New-PSDrive -Name RemoteHPoncfg -PSProvider FileSystem -Root “\\$strServerName\C$\Program Files\HP\hponcfg”
    cd RemoteHPoncfg:\
    cp C:\Scripts\GetInfo\GetNet.txt .\
    # Now that the file has been copied, don’t forget to remove the drive mapping
    cd c:
    Remove-PSDrive RemoteHPoncfg

    # If you are executing this script within a loop of multiple servers you should also initialize your variables to NULL for each iteration of the loop.
    $strILOIPReturnString=$null
    $strILOIP=$null
    $strILONAMEReturnString=$null
    $strILONAME=$null
    $strILODOMAINReturnString=$null
    $strILODOMAIN=$null
    $strILOMACReturnString=$null
    $strILOMAC=$null
    $strILOFQDN = $null

    # Remotely execute the hponcfg command using psexec.exe. Because I was working with older OSs (Win2000 and Server 2003) I could not use the
    # built-in powershell method of executing remote commands.
    if (($strILOGetNETReturnString = (&C:\bin\pstools\psexec.exe -accepteula \\$strServerName “C:\Program Files\HP\hponcfg\hponcfg.exe” /f “C:\Program Files\HP\hponcfg\GetNet.txt”) 2> $null) -match “Script succeeded”)
    {

    # Parse out the values that you want. I wanted IP address, Name, Domain and MAC address.
    # I put the regex parsing within a test for NOT NULL because some of the older iLOs did not have results for all values (EG: MAC was missing on iLO v1)

    $strILOIPReturnString = $strILOGetNETReturnString | Select-String -Pattern “<IP_ADDRESS VALUE=" -SimpleMatch
    if($strILOIPReturnString -ne $null) {$strILOIP = ([regex]::Match($strILOIPReturnString, '(?<=")(.+)(?=")')).Value}

    $strILONAMEReturnString = $strILOGetNETReturnString | Select-String -Pattern "<DNS_NAME VALUE=" -SimpleMatch
    if ($strILONAMEReturnString -ne $null) {$strILONAME = ([regex]::Match($strILONAMEReturnString, '(?<=")(.+)(?=")')).Value}

    $strILODOMAINReturnString = $strILOGetNETReturnString | Select-String -Pattern "<DOMAIN_NAME VALUE="-SimpleMatch
    if ($strILODOMAINReturnString -ne $null) {$strILODOMAIN = ([regex]::Match($strILODOMAINReturnString, '(?<=")(.+)(?=")')).Value}

    $strILOFQDN = $strILONAME + "." + $strILODOMAIN

    $strILOMACReturnString = $strILOGetNETReturnString | Select-String -Pattern "<MAC_ADDRESS VALUE=" -SimpleMatch
    if ($strILOMACReturnString -ne $null) {$strILOMAC = ([regex]::Match($strILOMACReturnString, '(?<=")(.+)(?=")')).Value}
    }

    Now that you have these values stored in variables you can use them any way that you want.

    I hope that this may help someone else out there.

    Enjoy.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.