Home » Read RSS feeds via Powershell

Read RSS feeds via Powershell

It’s very easy to read RSS feeds via Powershell. You just need to use Invoke-WebRequest and convert the output to XML:

$chfeed = [xml](Invoke-WebRequest "https://codehollow.com/feed/")
$chfeed.rss.channel.item | Select-Object @{Name="Id";Expression={$_."post-id".InnerText}}, title, link, pubDate

Result:
20161020_01_powershell

As we can see, it returns only 10 entries. So…

How to get older RSS feeds via Powershell?

It’s not so easy because it depends on the RSS type – ATOM e.g. works with “?page=2” … Other feed types do not support paging. If it’s an RSS 2.0 feed, then you can simply add “?paged=2” to the URL and you’ll get the second page.

Let’s use this information to create a Powershell script that returns all entries of a RSS feed:

$i = 1
while($true) {

    try { $chfeed = [xml](Invoke-WebRequest "https://codehollow.com/feed/?paged=$i") }
    catch { break; }

    $chfeed.rss.channel.item | Select-Object @{Name="Id";Expression={$_."post-id".InnerText}}, title, link, pubDate
    
    $i++
}

Result:
20161020_02_powershell

One comment

  1. Albert F says:

    Just used this today. Thank you! Powershell scripting guy blog didn’t cover what you did. Casting as [xml] did the trick along with a little navigation prompting.

Leave a Reply

Your email address will not be published. Required fields are marked *