Monday, 22 November 2010

Enabling and configuring SharePoint RSS feeds at the site level with PowerShell

When you create a new site collection in SharePoint 2010, the option to publish lists as RSS feeds may be switched off by default, depending on the site template used. It is easy enough to switch on for the site collection by going to Site Actions > Site Settings > RSS in the UI and ticking the Allow RSS feeds in this site collection checkbox.

image

Once this option is selected, the Allow RSS feeds in this site option is then also enabled for each site in the site collection. So, that’s easy right? Well, yes, but there are still a couple of things to consider:

  • Once these site options are selected, RSS feeds are automatically enabled for every list in each site – What if you want to leave RSS feeds on lists disabled and only enable the lists you wish to publish?
  • The Advanced Settings shown in the screenshot above apply on a site-by-site basis. If you wanted to set the same channel elements across all sites in the site collection, then this would mean going to each site, accessing the RSS settings, and typing in the same Advanced Settings every time. Not bad if you only have three sites, but very time consuming if you have 100’s!

The following PowerShell script performs the following tasks to try and ease the pain:

  • Enables RSS feeds on the site collection
  • Enables RSS feeds on each site in the site collection
  • Configures the Advanced Settings on each site in the site collection
  • Disable RSS feeds on each list in each site in the site collection

#Get site collection object
$site = Get-SPSite -Identity http://portal

#Enable RSS feeds in the site collection
$site.SyndicationEnabled = $true

#Step through each site in the site collection
$site | Get-SPWeb -Limit All | ForEach-Object {

    #Enable RSS feeds on this site
    $_.SyndicationEnabled = $true

    #Change properties exposed on the RSS administration page
    $_.AllProperties["vti_rss_Copyright"] = "Get-SPScripts"
    $_.AllProperties["vti_rss_ManagingEditor"] = "Phil Childs"
    $_.AllProperties["vti_rss_WebMaster"] = ""
    $_.AllProperties["vti_rss_TimeToLive"] = 60

    #Set FeedFormat property as configured by RSS administration page
    $_.AllProperties["vti_rss_FeedFormat"] = "Rss20"

    #Update site object and post message to console
    $_.Update()
    write-host "Changed RSS settings on site:" $_.Title
   
    #Disable RSS Feeds on all lists – remove this if/else statement if you want to leave them enabled
    $_.Lists | ForEach-Object {
   
        if ($_.EnableSyndication –eq $true)
        {
            $_.EnableSyndication = $false
            $_.Update()
            write-host "RSS Feeds disabled on list:" $_.Title
        }
        else
        {
            write-host "RSS Feeds already disabled on list:" $_.Title
        }
    }
}

#Dispose of site object
$site.Dispose()

One item to note here is the $_.AllProperties["vti_rss_FeedFormat"] = "Rss20" line. This must set the RSS version to 2.0, but there is no option in the interface to change this – it gets added automatically by SharePoint when you configure the site RSS feed settings in the UI, so I have included it in the script to emulate the same behaviour.

If you’re wondering how to use PowerShell for configuring RSS settings on lists, I’ll be covering this in a future post soon…

11 comments:

  1. Almost exactly what I was looking for. Here's my question. On an announcement list, is there any way to change what fields are included in the feed? I have a situation where I have a bunch of sites with announcement rss feeds, and the announcements lists have a few custom fields, which are included in the RSS feed by default. I'd like to turn them off. Can this happen with PowerShell?

    ReplyDelete
  2. Hi Kyle,

    I'll be looking at RSS settings on lists soon and will post an article - hopefully I can get exactly what you were looking for next time :-)

    ReplyDelete
  3. EXCELLENT information. Your directions are clear and concise, and easy to follow. Thanks for your hard work in posting this info.

    ReplyDelete
  4. Thanks for sharing these information. It’s a very nice topic. We are providing online training classes dotnet-online-training

    ReplyDelete