Dynamic object manipulation in Powershell?

280 Views Asked by At

I was trying my hand at the Iron Scripter challenge 3, which tasks us with crawling an RSS feed and retrieving pieces of info. I did this by capturing each element as a property of a new object using foreach. The problem I run into is this: Since I used a foreach, the objects do not have unique names, so I cannot call their individual properties. I'm looking for a method of uniquely identifying each object, so they can be called individually. Additionally, the $entry.creator output comes through as "creator", but if I just type in $entry.creator, the authors name shows properly.

[xml]$rss = Invoke-WebRequest -Uri 'https://powershell.org/feed'
$rss2 = $rss.rss.channel.item
$i = [int]1
foreach($entry in $rss2){
$out = New-Object PSObject -property @{
                    Number = $i++
                    Title = $entry.title
                    Date = $entry.pubDate
                    Link = $entry.link
                    Author = $entry.creator
             }
$out
 }
0

There are 0 best solutions below