tags:

views:

643

answers:

2

When I connect to my HP ILO using the URL, http://ilo-ip/xmldata?item=All it is returning a XML file in below format.

  <?xml version="1.0" ?> 
- <RIMP>
- <HSI>
  <SPN>ProLiant DL385 G1</SPN> 
  <SBSN>ABCDEFG</SBSN> 
  <UUID>123456789</UUID> 
  </HSI>
- <MP>
  <ST>1</ST> 
  <PN>Integrated Lights-Out (iLO)</PN> 
  <FWRI>1.82</FWRI> 
  <HWRI>ASIC: 2</HWRI> 
  <SN>ILOABCDEFG</SN> 
  <UUID>ILO1234545</UUID> 
  </MP>
  </RIMP>

Is there any powershell command/script to read XML data from web URL?

+2  A: 

Hi,

PowerShell uses the .Net framework XmlDocument so you could call the load method to load the xml into an XmlDocument object like this:

#Option 1    
$doc = New-Object System.Xml.XmlDocument
$doc.Load("http://ilo-ip/xmldata?item=All")

#Option 2
[xml]$doc = (New-Object System.Net.WebClient).DownloadString("http://ilo-ip/xmldata?item=All")


# Your XML will then be in the $doc and the names of the XML nodes can be used as
# properties to access the values they hold. This short example shows how you would
# access the value held in the SPN nodes from your sample XML 
Write-Host $doc.RIMP.HSI.SPN

If your looking for more information on working with the XML once it has been loaded check out Dr. Tobias Weltner's eBook at PowerShell.com, chapter 14 covers XML.

Alan
Thanks for your reply. How do I read the code that is loaded? I couldn't find much help in internet.
Sitaram Pamarthi
the XML will be held in the $doc object so you can access it via property notation. For example Write-Host $doc.RIMP.HSI.SPNThis will write "ProLiant DL385 G1" to the console. What you can do is pipe $doc to Get-Member to get a list of properties e.g.$doc | Get-Member
Alan
+3  A: 

Sure. You can use the .NET WebClient object to download XML from the web and then use the [xml] type to interpret a string as XML like so:

$url = "http://blogs.msdn.com/powershell/rss.xml"
[xml]$xml = (new-object System.Net.WebClient).DownloadString($url)
$xml.rss.channel | Foreach {$_.item} |
    Where {[DateTime]$_.pubDate -gt (Get-Date).AddMonths(-1)} |
    Format-Table Title
Keith Hill