PoshCode Logo PowerShell Code Repository

Get-FeedInfo (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1698"></script>download | new post

Takes an array of RSS feed URLs and gets the site URL and title..

  1. function Get-FeedInfo([string[]]$feeds) {
  2. # $feeds is an array of rss/atom URLs
  3. $blogs=@(); $broken=@(); $feeds = $feeds | sort -unique {$_}
  4. foreach($feed in $feeds){
  5.    try {
  6.       $xml = Get-WebPageContent $feed;
  7.    } catch {
  8.       $broken += $feed
  9.       $xml = $null
  10.    }
  11.    if($xml.html.rss) { $xml = $xml.html; write-warning $feed }
  12.    if($xml.rss) {
  13.       $blogs += New-Object PSObject -Property @{
  14.          title= $xml.rss.channel.title
  15.          link = $xml.rss.channel.link | ? { $_ -is [string] }
  16.          feed = $feed
  17.       }
  18.    } elseif($xml.feed) {
  19.       $blogs += New-Object PSObject -Property @{
  20.          title= $xml.feed.title.'#text'
  21.          link = $xml.feed.link |? {$_.rel -eq 'alternate' } | select -expand href
  22.          feed = $feed
  23.       }
  24.    } else {
  25.       $broken += $feed
  26.       $blogs += New-Object PSObject -Property @{ feed = $feed }
  27.    }
  28. }
  29. Write-Output $blogs, $broken
  30. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me