XML : How to loop through grouped XML nodes in Powershell

I have an xml document in this format

  <rss>    <channel>      <item>        <id>1</id>        <image>img_32.jpeg</image>      </item>      <item>        <id>2</id>        <image>img_42.jpeg</image>      </item>      <item>        <id>1</id>        <image>img_52.jpeg</image>      </item>      <item>        <id>3</id>        <image>img_62.jpeg</image>      </item>      <item>        <id>4</id>        <image>img_72.jpeg</image>      </item>    </channel>    </rss>    

The ID node is not unique, what i'd like to do using powershell is group by the ID, then loop through the grouped items for each ID.

  ID 1 has two images    loop through the two images      do something with it    ID 2 has one image    loop through the one image      do something with it    etc..    

So far i have the following

  [xml]$xml = (New-Object System.Net.WebClient).DownloadString("https://myfeedurl.xml")  $grouped = $xml.rss.channel.item | Group id  $grouped    

Which returns

  Count Name        Group  ----- ----        -----      2 1           {item}{item}      1 2           {item}      1 3           {item}      1 4           {item}    

But i can't figure how use this grouped information in order to end up with a list of unique grouped ID items so i can easily loop through the images.

No comments:

Post a Comment