Generating RSS Feeds

Feed Scripts are regular PowerShell scripts, but with the .rs1x and .as1x extension. When the scripts are executed by PowerShell Server, the objects returned to the pipeline by the script are automatically converted to RSS items, based on these rules:

  • Each object returned by the pipeline becomes one RSS item.
  • If the object is just a regular primitive value, like a string or number, its value is used as the title of the RSS entry.
  • If the object is an array, then each item in the array is written as a <value> element in the RSS entry
  • If the object is a hashtable, then each key/value pair in it is written as an element in the RSS entry, using the key as the element name.

Here's an example script that would generate 3 RSS entries:

# A simple value translates into an item with only a title
"This is a simple Item"

#An array translates into a single item (but no title)
,('an', 'array')

# a hashtable allows you to set your own element names
@{ 'name' = 'John'; Value = 'Doe' }

Customizing RSS Entry Generation

If you need finer control over how the objects returned by your scripts get translated into RSS entries, return hashtable objects instead. These allow you to specify the names and values of the elements in the RSS feed entry. They also allow you to override values for some basic RSS entry properties by prefixing the keys with 'rss:' or 'atom:'.

Here is an example that generates a feed from the list of files in the C: drive, and customizes how the entries are translated:

ls c:\ | %{
      'rss:id' = "urn:$($_.Name)";
      'rss:updated' = $_.LastWriteTime.ToString('R');
      'rss:title' = $_.Name;
      'fullname'  = $_.FullName;
      'size' = $_.Length;
      'directory' = $_.PSIsContainer;
      'Mode' = $_.Mode;

Overriding Feed Attributes

By default, PowerShell ASP will provide some basic information about your script in the feed metadata. For example, the title of the feed will be the file name of your *.rs1x script.

You can customize the values of these attributes by calling the Set-FeedAttr function from within your script. The arguments you need to provide are the name of the attribute and its value.

set-feedattr 'rss:title' 'This is a sample feed'
set-feedattr 'rss:link' 'http://my.feed.url/'

Generating Atom feeds

PowerShell ASP will generate RSS feeds by default for .rs1x scripts and ATOM feeds for .as1x scripts You can force RSS generation for an ATOM feed by appending "?@rss" to the Query String in the feed URL. Likewise, you can force ATOM generation for an RSS feed by appending "?@atom" to the Query String in the feed URL.

Copyright (c) 2022 /n software inc. - All rights reserved.
PowerShell Server 2020 - Version 20.0 [Build 8165]