Robert van den Nieuwendijk created the basis of this script and shared it on the VMware Communities. The problem I had with the original script was the default SSL certificate which HP uses on the iLO adapters. This resulted in an error and the script failed to return the XML file. So I started a search query on Google and found a post by Paul Brice who had the same problem while getting information via XML on an Iron Port setup. I tried his code to open the iLO XML information and it worked like a charm.

So I updated the script from Robert and added the information from Paul to it. The last thing I changed was the $url and added a RegEx to return the digits from the ESX hostname. For example esx72, the RegEx will return the 72.

Get-VMHost | Where-Object {$_.Manufacturer -eq "HP"} | `
Sort-Object -Property Name | ForEach-Object {
    $VMHost = $_
    $netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection])
    IF($netAssembly) {
        $bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic"
        $settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal")
        $instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @())
        
        if($instance) {
            $bindingFlags = "NonPublic","Instance"
            $useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags)

            if($useUnsafeHeaderParsingField) {
                $useUnsafeHeaderParsingField.SetValue($instance, $true)
            }
        }
    }

    [int]$ip = (([regex]'\d+').matches($vmhost.Name) | select Value).Value

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    $url = "https://192.168.1.$ip/xmldata?item=All"
    $xml = New-Object System.Xml.XmlDocument
    $xml.Load("$url")
        New-Object PSObject -Property  @{
            "Name" = $VMHost.Name
            "Serial Number" = $xml.RIMP.HSI.SBSN
            "ILO Serial Number" = $xml.RIMP.MP.SN
            "ILO Type" = $xml.RIMP.MP.PN
            "ILO Firmware" = $xml.RIMP.MP.FWRI    
          }
} | Export-Csv -NoTypeInformation -UseCulture -Path C:\EsxSerialNumbers.csv 

The output of the script will be exported to a CSV file.

Advertisement

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 )

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.