-
Notifications
You must be signed in to change notification settings - Fork 14
/
Out-RssFeed.ps1
69 lines (65 loc) · 4.24 KB
/
Out-RssFeed.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function Out-RssFeed
{
<#
.Synopsis
Outputs RSS items into an RSS feed
.Description
Outputs RSS items into an RSS feed. Items can be easily created with New-RssItem
.Example
New-RssItem -Title "My Vacation" -Category Stupid, Stuff -Link http://bit.ly/myvacation -Author Bob -Description "Stuff I did on my vacation" |
Out-RssFeed -Title "My Blog" -Description "Things I Decided To Say to the World" -Link "http://my.blog"
.Link
New-RssItem
#>
[OutputType([String])]
param(
# An Rss Item
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[ValidateScript({
$asXml = $_ -as [xml]
if ((-not $asxml.Item)) {
throw "The root of a format XML most be an item element"
}
return $true
})]
[string[]]
$Item,
# The title of the RSS feed
[Parameter(Mandatory=$true)]
[string]$Title,
# The description of the RSS feed
[Parameter(Mandatory=$true)]
[string]$Description,
# The date the feed was published
[DateTime]$DatePublished = [DateTime]::UtcNow,
# A Link to the feed page
[Parameter(Mandatory=$true)]
[Uri]$Link
)
begin {
$rssItems = New-Object Collections.ArrayList
}
process {
$null = $rssItems.Add(($Item -join "
"))
}
end {
$rssXml = [xml]@"
<rss version="2.0">
<channel>
<title>$([Security.SecurityElement]::Escape($title))</title>
<creator>$([Security.SecurityElement]::Escape($Author))</creator>
<pubDate>$($DatePublished.ToString('r'))</pubDate>
<description>$([Security.SecurityElement]::Escape($description))</description>
<link>$([Security.SecurityElement]::Escape($link))</link>
$($rssItems -join '')
</channel>
</rss>
"@
if (-not $rssXml) { return }
$strWrite = New-Object IO.StringWriter
$rssXml.Save($strWrite)
$prettyXml = "$strWrite"
$prettyXml.Substring($prettyXml.IndexOf(">") + 3)
}
}