How to read XML file from web using powershell

Tags: xml powershell

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> 
- <MP>
  <PN>Integrated Lights-Out (iLO)</PN> 

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

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

#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, chapter 14 covers XML.

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 = ""
[xml]$xml = (new-object System.Net.WebClient).DownloadString($url)
$ | Foreach {$_.item} |
    Where {[DateTime]$_.pubDate -gt (Get-Date).AddMonths(-1)} |
    Format-Table Title

This video can help you solving your question :)
By: admin