SharePoint Online: How to Enable Rating in List using PowerShell?

Requirement: Enable Rating in SharePoint Online List.

How to Enable Rating in SharePoint Online?

The rating feature in SharePoint Online helps to highlight documents and list items. The rating can be enabled in the SharePoint Online list and libraries to let users see and rate items. The rating can be configured as either star ratings or likes.

  1. Star Ratings
    When a list is configured for star ratings, Every time someone rates an item or a document, the scale displays the average rating of all those who rated it. To rate an item within a list, click on the star that represents the rating you want to give the item. Once you select the rating, the item is updated to include your rating. If you rate the item again, the previous rating applied is replaced by the newly selected rating.
  2. Like Ratings
    Likes are similar to what you use on Facebook, Twitter, and LinkedIn, etc. When the rating type is set to “Likes”, items are presented with the like button (little heart icon), which includes the number of Likes an item has received. You can like an item if you have not yet done so or unlike the item, if you have already liked it. You can record your like/unlike by clicking the like icon.

To enable ratings, we must activate it under list settings. To activate them, do the following:

  1. Navigate to the SharePoint Online list or library where you want to activate ratings.>> Click on List Settings
  2. On the List Settings page, click on the “Rating Settings” link under the General Settings section.
  3. On the Rating Settings, Set the “Allow items in this list to be rated” option to “Yes”
  4. For the “Which voting/rating experience you would like to enable for this list” option, select either Star Ratings or Like.rating settings in sharepoint online
  5. Click the OK button to save the changes.

The ratings for the list will be enabled. If you don’t see rating settings under list settings, You have to activate the Rating feature! How to Activate Rating Feature in SharePoint Online?

sharepoint online enable rating

PowerShell to Enable Rating Settings in SharePoint Online:

Configuring rating settings in a SharePoint Online list or library is a bit tricky as there is no direct method to set ratings. We need to perform below steps:

  1. Add Rating site columns to the list
  2. Add Rating Fields to the Default view
  3. Set List Root Folder’s Property bag value.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to Add Fields to List 
Function Add-SPOSiteColumnToList([Microsoft.SharePoint.Client.List]$List, [GUID]$FieldID)
{
    #Get Fields from List
    $Ctx.Load($List.Fields)
    $Ctx.ExecuteQuery()
    
    #Get the Site Column from Web
    $SiteColumn = $List.ParentWeb.AvailableFields.GetById($FieldID)
    $Ctx.Load($SiteColumn)
    $Ctx.ExecuteQuery()

    #Check if the Field exist in list
    $ListField = $List.Fields | where {$_.ID -eq $SiteColumn.Id}
    if($ListField -eq $NULL)
    {
        #Add the site column to the list
        $NewColumn = $List.Fields.Add($SiteColumn)
        $ctx.ExecuteQuery()
        Write-host "Site Column '$($SiteColumn.Title)' Added to the List Successfully!" -f Green
    }
}

Function Set-SPOListRatingSettings([string]$SiteURL, [string]$ListName, [string]$RatingsType)
{
    #Setup Credentials to connect
    $Cred = Get-Credential

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $Ctx.ExecuteQuery()

    #Rating Site Columns
    $AverageRatingFieldID = [guid]"5a14d1ab-1513-48c7-97b3-657a5ba6c742"
    $RatingCountFieldID = [guid]"b1996002-9167-45e5-a4df-b2c41c6723c7"
    $RatedByFieldID = [guid]"4D64B067-08C3-43DC-A87B-8B8E01673313"
    $RatingsFieldID = [guid]"434F51FB-FFD2-4A0E-A03B-CA3131AC67BA"
    $LikesCountFieldID = [guid]"6E4D832B-F610-41a8-B3E0-239608EFDA41"
    $LikedByFieldID = [guid]"2CDCD5EB-846D-4f4d-9AAF-73E8E73C7312"

    #Call the function to Add Rating Site columns to the List
    Add-SPOSiteColumnToList -List $List -FieldID $AverageRatingFieldID
    Add-SPOSiteColumnToList -List $List -FieldID $RatingCountFieldID
    Add-SPOSiteColumnToList -List $List -FieldID $RatedByFieldID
    Add-SPOSiteColumnToList -List $List -FieldID $RatingsFieldID
    Add-SPOSiteColumnToList -List $List -FieldID $LikesCountFieldID
    Add-SPOSiteColumnToList -List $List -FieldID $LikedByFieldID

    #Update Field to Default view
    $ListDefaltView = $List.DefaultView
    $ViewFields = $ListDefaltView.ViewFields
    $Ctx.Load($ListDefaltView)
    $Ctx.Load($ViewFields)
    $Ctx.ExecuteQuery()

    If($RatingsType -eq "Ratings")
    {
        #Add Ratings Fields to default view
        If($ViewFields -notcontains "AverageRating")
        {        
            $ListDefaltView.ViewFields.Add("AverageRating")
            $ListDefaltView.Update()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Ratings Field Added to the Default View!"
        }
        #Remove Likes Field from Default View
        If($ViewFields -contains "LikesCount")
        {        
            $ListDefaltView.ViewFields.Remove("LikesCount")
            $ListDefaltView.Update()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Likes Field Removed from the Default View!"
        }
    }
    ElseIf ($RatingsType -eq "Likes")
    {
        #Add Likes Fields to default view
        If($ViewFields -notcontains "LikesCount")
        {        
            $ListDefaltView.ViewFields.Add("LikesCount")
            $ListDefaltView.Update()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Likes Field Added to the Default View!"
        }
        #Remove Ratings Field from Default View
        If($ViewFields -contains "AverageRating")
        {        
            $ListDefaltView.ViewFields.Remove("AverageRating")
            $ListDefaltView.Update()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Rating Field Removed from the Default View!"
        }
    }
    Else #Disable Rating!
    {
        #Remove Ratings Field from Default View
        If($ViewFields -contains "AverageRating")
        {        
            $ListDefaltView.ViewFields.Remove("AverageRating")
            $ListDefaltView.Update()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Rating Field Removed from the Default View!"
        }
        #Remove Likes Field from Default View
        If($ViewFields -contains "LikesCount")
        {        
            $ListDefaltView.ViewFields.Remove("LikesCount")
            $ListDefaltView.Update()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Likes Field Removed from the Default View!"
        }
    }

    #Set Rating Setting for the List
    $RootFolder = $List.RootFolder
    $RootFolderProperties = $RootFolder.Properties
    $Ctx.Load($RootFolder)
    $Ctx.Load($RootFolderProperties)
    $RootFolderProperties["Ratings_VotingExperience"] = $RatingsType
    $RootFolder.Update()
    $Ctx.ExecuteQuery()
    Write-host -f Green "Rating Settings Updated for the List!"
}
#Set Variables
$SiteURL= "https://crecent.sharepoint.com/sites/Marketing"
$ListName="Team Documents"
$RatingsType = "Ratings" #Ratings or Likes or "" (To Disable!)

#Call the function to set rating settings in list
Set-SPOListRatingSettings -SiteURL $SiteURL -ListName $ListName -RatingsType $RatingsType 

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

4 thoughts on “SharePoint Online: How to Enable Rating in List using PowerShell?

  • go to your site pages library > Advanced setting > and set the experience to New or Default

    Reply
  • Dear Salaudeen, I read that the rating feature is only available for team sites. Do you know if there is any possibility to also achieve such a functionality for a list of a communication site? There is no possibility for us to change to a team site.

    Reply
  • After Enabling Star Rating in SPO Modern library, Disp form and edit form opens in Classic mode . Is there way to open it in Modern view?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *