Monday, October 17, 2011

SharePoint 2010 : How to add rating to a list using PowerShell

Rating an item of a list is one of the new features of SharePoint 2010. Lately I was asked how  to  add this feature programmatically to the Page list of a publishing site. First, I was expecting to find a sort of SPList.EnableRating property or something like that. There is no such a thing. 

Via the UI, on the list settings page, you just have to click the Ratings settings link and then select YES.  When you enable Ratings on a list, SharePoint adds two columns to the content type(s) you choose : AverageRatings and RatingCount

Finally, after some readings and few searches, here is how I made it using PowerShell :

First, we have to activate a site scoped  feature called Ratings with ID 915c240e-a6cc-49b8-8b2c-0bff8b553ed3 :

Enable-SPFeature -Identity Ratings -Url http://SiteCollectionUrl 

Then, we add the two columns to the content type(s) of the list :

 $site = New-Object Microsoft.SharePoint.SPSite("http://SiteCollectionUrl")  
 if ($web -ne $Null)  
       if ($PagesList -ne $Null)  
             Write-Host " Processing List : " $PagesList.Title  
             If ($ct -ne $null)  
                   Write-Host " Adding Rating columns to content type : " $  
                   $AverageRatinglink = new-object Microsoft.SharePoint.SPFieldLink $AverageRating  
                   $RatingCountLink = new-object Microsoft.SharePoint.SPFieldLink $RatingCount  

Hope this helps 


  1. Hi i am using the following command for sharepoint 2010 but it is giving me the following error:

    New-Object : Constructor not found. Cannot find an appropriate constructor for
    type Microsoft.SharePoint.SPFieldLink

    Please Help

  2. Hi Ian,

    Did you activate the 'ratings' feature as mentioned? If you did not please do. Otherwise, please post your code that I can help you diagnose the problem.


  3. I am vary interested in your post and that is very helpful and useful for me. I like it very much and that is more shareable. Thanks for share it with us.