Using PowerShell to download XML, and save as CSV file?


I'm fairly new to PowerShell, but have a strong C# background.

The task I'm trying to accomplish is to download some XML, and then save some of the elements from the XML file in a .csv file. I don't need all the elements from the XML, just a few items.

The XML looks something like this:

      <....lots more properties and subnodes I don't need>

I've managed to download the XML using something like this:

$downloaded = ([Xml](New-Object Net.WebClient).DownloadString(""))

Now I need to extract just a few of the properties from the XML, and export it to CSV file.

I understand that I can reach the data with $[0].InputData.Firstname, but need some advice on how to extract a few of the properties and save as CSV.


XSLT is a (the?) standard way when it comes to transforming XML to something else.

<xsl:stylesheet version="1.0" xmlns:xsl="">
  <xsl:output method="text" />

  <xsl:template match="InputData">
    <xsl:value-of select="concat('"', Id, '"')" />
    <xsl:value-of select="','" />
    <xsl:value-of select="concat('"', Firstname, '"')" />
    <xsl:value-of select="','" />
    <xsl:value-of select="concat('"', Lastname, '"')" />
    <xsl:value-of select="&#10;" />


Some Powershell context: XSLT with Powershell

By : Tomalak

you could do something like:

$ | %{ $_.InputData }`
| select Firstname,Lastname `
| Export-Csv -path foo.csv -NoTypeInformation

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