Created
October 6, 2015 11:54
-
-
Save KirillPashkov/ab39f4111574ada9604b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-RssFeed | |
{ | |
<# | |
.SYNOPSIS | |
Reads RSS feeds from supplied URI and outputs every possible property | |
.PARAMETER URI | |
Parameter supports one or more URIs representing RSS feeds | |
.EXAMPLE | |
Get-RSSFeed -uri 'http://powershell.com/cs/blogs/MainFeed.aspx','http://rss.msn.com/' | Out-GridView | |
Pulls the RSS feed from both msn.com and powershell.com, and displays every available property. | |
.EXAMPLE | |
'http://powershell.com/cs/blogs/MainFeed.aspx' | Get-RssFeed | Export-CSV "$env:TEMP\RssFeed.csv" -NoTypeInformation -UseCulture | |
Pulls the RSS feed from powershell.com using pipeline input, and exports every available property to a csv file. | |
#> | |
[CmdLetBinding()] | |
Param ( | |
[Parameter(Mandatory=$True, ValueFromPipeline=$True)] | |
[string[]]$Uri | |
)#param | |
Begin{}#begin | |
Process { | |
foreach ($target in $uri) { | |
[xml]$xml=(Invoke-WebRequest -Uri $target -ContentType 'text/xml' -Proxy 'http://sgo-ap060:8080' -ProxyUseDefaultCredentials).Content | |
$set=@() | |
$xml.rss.channel.item | | |
ForEach-Object { | |
$item=$_ | |
if($item.title) | |
{ | |
$obj=New-Object PSObject | |
($xml.rss.channel.item | | |
Get-Member -MemberType Properties | | |
Sort-Object -Descending).name | | |
ForEach-Object { | |
$rssitem=$_ | |
if ($item.$rssitem.'#text'){$rssvalue=($item.$rssitem.'#text' -join ', ')}#in case there is multiple elements, such as Categories | |
else {$rssvalue=$item.$rssitem} | |
$obj| Add-Member -MemberType NoteProperty -Name $rssitem -Value $rssvalue | |
}#ForEach-Object | |
$set+=$obj | |
}#ForEach-Object | |
} | |
$set | |
}#foreach | |
}#process | |
End{}#end | |
}#function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment