Reading RSS feeds in PowerShell

Most of you are probably subscribed to a few RSS feeds, personally, I use Feedly for them in my browser as an extension and as an app on my phone. But wouldn’t it be nice to see that feed in a PowerShell session with links you can click on to read them more in your browser? This blog post will show you how to read and display them in PowerShell.

What’s RSS?

“RSS stands for Really Simple Syndication. It’s an easy way for you to keep up with news and information that’s important to you, and helps you avoid the conventional methods of browsing or searching for information on websites.”

How do I know if a website uses RSS?

Some sites have a built-in RSS feed like, for example, this website. You can append “/feed” in the URL (https://powershellisfun.com/feed) and it will show you something like this: (You can see this article in the screenshot 😉 )

Other sites have a button like this one somewhere on the page:

Clicking on it will show you the RSS feed content and the URL will change to the one that you need to subscribe to in your RSS reader.

Script for retrieving an RSS feed

Below is a simple version of retrieving the news from my site:

$total = foreach ($item in Invoke-RestMethod -Uri http://powershellisfun.com/feed ) {
    [PSCustomObject]@{
        'Publication date' = $item.pubDate
        Title              = $item.Title
        Link               = $item.Link
    }
}

$total | Sort-Object { $_."Publication Date" -as [datetime] } 

This will give you the following output:

Adjusting the number of items to show

The output from above shows all items posted from the 27th of May until Sunday 29 May. This could be a little too much on a site that posts a lot of things every day. Below is the same script with a configurable number of items to select, it selects the last x number of items specified which is 5 in this example:

$numberofitems = '5'
$total = foreach ($item in Invoke-RestMethod -Uri http://powershellisfun.com/feed ) {
    [PSCustomObject]@{
        'Publication date' = $item.pubDate
        Title              = $item.Title
        Link               = $item.Link
    }
}

$total | Sort-Object { $_."Publication Date" -as [datetime] } |  Select-Object -Last $numberofitems

and this will output like this:

Refreshing the news in a Windows Terminal Window

The Windows Terminal has a nice feature of adding an extra window, you can do this by holding ALT and selecting the new tab that you want:

Which looks like this:

In the window on the right side you can run the same script but with a loop in it to refresh it every 10 minutes:

while ($true) {
    Clear-Host
    $NumberOfItems = '5'
    $total = foreach ($item in Invoke-RestMethod -Uri http://powershellisfun.com/feed ) {
        [PSCustomObject]@{
            'Publication date' = $item.pubDate
            Title              = $item.Title
            Link               = $item.Link
        }
    }

    $total | Sort-Object { $_."Publication Date" -as [datetime] } |  Select-Object -Last $NumberOfItems
    Start-Sleep -Seconds 600
}

This will look something like this and is a nice way to follow news if you have a big monitor 😉

Happy RSS reading!

Download the script(s) from GitHub here

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.