PSWebToolbox.psm1
function Format-AtomFeed { param ($Feed) $Entries = foreach ($Entry in $Feed) { [PSCustomObject][ordered] @{ID = $Entry.id Title = $Entry.title Link = $Entry.link PublishDate = if ($Entry.published -is [DateTime]) { [DateTime] $Entry.published } else { $Entry.published } } } return $Entries } function Format-RSSFeed { param ($Feed) $Entries = foreach ($Entry in $Feed) { [PSCustomObject][ordered] @{Title = $Entry.title Link = $Entry.link PublishDate = if ($Entry.pubDate -is [DateTime]) { [DateTime] $Entry.pubDate } else { $Entry.pubDate } Creator = $Entry.Creator.'#cdata-section' Categories = ($Entry.Category.'#cdata-section' | Sort-Object -Unique) -join ',' isPermaLink = $Entry.Guid.isPermaLink LinkPerm = $Entry.Guid.'#text' Description = $Entry.description.'#cdata-section' } } return $Entries } function Get-RSSFeed { [CmdletBinding(DefaultParameterSetName = 'Count')] param([Parameter(ValueFromPipeline)][System.Uri[]] $Url, [Parameter(ParameterSetName = 'Count')][nullable[int]] $Count = 10, [Parameter(ParameterSetName = 'All')] [switch] $All, [switch] $CategoriesOnly) Begin { [Object] $FeedGlobal = $null switch ($PsCmdlet.ParameterSetName) { 'All' { $Count = $null; break } 'Count' { break } } } Process { [int] $PageCount = 1 [System.Uri] $BuildURL = "$Url" [Object] $Feed = $null while ($true) { Write-Verbose "Get-Feed - Count: $($Feed.Count) Expected Count: $Count URL: $BuildURL" try { $Feed += Invoke-RestMethod -Uri $BuildURL -Verbose:$false } catch { $ErrorMessage = $_.Exception.Message -replace "`n", " " -replace "`r", " " if ($PageCount -eq 1) { Write-Warning "Get-Feed - Url: $Url CurrentUrl: $BuildURL Error: $ErrorMessage" } else { } break } if ($All) { $FeedGlobal += $Feed } elseif ($Count) { if ($Feed.Count -ge $Count) { $FeedGlobal += $Feed | Select-Object -First $Count break } } else { break } $PageCount++ $BuildURL = "$Url/?paged=$PageCount" } } End { $Value = Format-RSSFeed -Feed $FeedGlobal if ($CategoriesOnly) { return $Value.Categories -Split ',' | Group-Object -NoElement | Sort-Object Count -Descending } else { Write-Verbose "Get-RssFeed - Returning $($Value.Count) articles" return $Value } } } Export-ModuleMember -Function @('Get-RSSFeed') -Alias @() |