2

In our Remote Management System we can execute HPiLOcmdlets to retrieve data from the iLO hardware management card in a HP Server.

Example:

$tempstatus = Get-HPiLOTemperature -Server $server -Username $Username -Password $Password -Output XML

This will generate an XML file, that i want to use as input and output as a table in Powershell

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<RIBCL VERSION="2.23">
   <TEMPERATURE>
      <TEMP>
         <LABEL VALUE="01-Inlet Ambient" />
         <LOCATION VALUE="Ambient" />
         <STATUS VALUE="0K" />
         <CURRENTREADING VALUE="23" UNIT="Celsius" />
         <CAUTION VALUE="42" UNIT="Celsius" />
         <CRITICAL VALUE="46" UNIT="Celsius" />
      </TEMP>
      <TEMP>
         <LABEL VALUE="02-CPU 1" />
         <LOCATION VALUE="CPU" />
         <STATUS VALUE="0K" />
         <CURRENTREADING VALUE="40" UNIT="Celsius" />
         <CAUTION VALUE="70" UNIT="Celsius" />
         <CRITICAL VALUE="N/A" />
      </TEMP>
      <TEMP>
         <LABEL VALUE="03-CPU 2" />
         <LOCATION VALUE="CPU" />
         <STATUS VALUE="0K" />
         <CURRENTREADING VALUE="49" UNIT="Celsius" />
         <CAUTION VALUE="70" UNIT="Celsius" />
         <CRITICAL VALUE="N/A" />
      </TEMP>
   </TEMPERATURE>
</RIBCL>

So far i tried :

[xml]$XmlDocument = get-content test.xml
$XmlDocument.RIBCL.TEMPERATURE.ChildNodes | Format-Table

Result:

xml

Wanted output:

xml

Thanks for any help !!!

2
  • 6
    Please edit the question and paste in as text the items you have in graphics. Make it easy for someone to copy from your question into their own testing and experimentation environment. Commented Jun 13, 2018 at 20:45
  • I will do the next time it was my first post, but thank you very much for making the post readble. Commented Jun 14, 2018 at 9:06

3 Answers 3

1

I didn't get the text 'celsius' in the table (because those columns are handled differently, but here's some code that splits up the xml the way you want. It just creates new objects with the value

[xml]$XmlDocument = get-content test.xml
$XmlDocument.RIBCL.Temperature.TEMP | foreach-object {
    $obj=[ordered]@{}
    foreach($node in $_.ChildNodes){
       $obj[$node.Name]=($node.Value+ " " + $node.Unit).Trim()
    }
    write-output ([pscustomobject]$obj)
  } | format-table 
Sign up to request clarification or add additional context in comments.

1 Comment

Including the unit is simple. Something like this would suffice: $obj[$node.Name] = ($node.Value + " " + $node.Unit).Trim()
0

The following code might work for you.

[xml]$XmlDocument = get-content hplio.xml

foreach ($r in $XmlDocument.RIBCL.TEMPERATURE.TEMP) {
    $info = [ordered]@{}
    $info.LABEL = $r.LABEL.VALUE
    $info.LOCATION = $r.LOCATION.VALUE
    $info.STATUS = $r.STATUS.VALUE
    $info.CURRENTREADING = $r.CURRENTREADING.VALUE + ' ' + $r.CURRENTREADING.UNIT
    $info.CAUTION = $r.CAUTION.VALUE + ' ' + $r.CAUTION.UNIT
    $info.CRITICAL = $r.CRITICAL.VALUE + ' ' + $r.CRITICAL.UNIT

    $reading = New-Object -TypeName PSObject -Prop $info
    Write-Output $reading
}

Sample output using .\temp.ps1 | ft

LABEL            LOCATION STATUS CURRENTREADING CAUTION    CRITICAL
-----            -------- ------ -------------- -------    --------
01-Inlet Ambient Ambient  0K     23 Celsius     42 Celsius 46 Celsius
02-CPU 1         CPU      0K     40 Celsius     70 Celsius N/A
03-CPU 2         CPU      0K     49 Celsius     70 Celsius N/A

Comments

0

In addition to the answers already given. The following also works.

[xml]$XmlDocument = get-content test.xml

$XmlDocument.RIBCL.TEMPERATURE.TEMP | Format-Table -Property @{LABEL="LABEL"; Expression={$_.LABEL.VALUE}}, 
    @{LABEL="LOCATION"; Expression={$_.LOCATION.VALUE}}, 
    @{LABEL="STATUS"; Expression={$_.STATUS.VALUE}}, 
    @{LABEL="CURRENTREADING"; Expression={$_.CURRENTREADING.VALUE + " " + $_.CURRENTREADING.UNIT}}, 
    @{LABEL="CAUTION"; Expression={$_.CAUTION.VALUE + " " + $_.CAUTION.UNIT}}, 
    @{LABEL="CRITICAL"; Expression={$_.CRITICAL.VALUE + " " + $_.CRITICAL.UNIT}}

1 Comment

@MarkDuncker glad it worked. Please remember to selected one of the provided solutions as the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.