Enable Rating or Likes Settings in SharePoint 2013

Hi Friends,

It was a tough time to find the PowerShell or a C# API to enable or disable Rating/Likes Settings in SharePoint 2013. I found a helpful post from Nanddeep for c# equivalent. I have converted it in PowerShell, hope this will help some of SharePoint developers and admins.

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue.

  1. $web=Get-SPWeb "http://abc.com/test";  
  2. $list=$web.Lists["Pages"];  
  3. if($list -ne $null)  
  4. {  
  5. Write-Host $list.Title "not null";  
  6. $assembly=[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")  
  7. $reputationHelper =$assembly.GetType("Microsoft.SharePoint.Portal.ReputationHelper");  
  8.   
  9. $bindings = @("EnableReputation""NonPublic""Static");  
  10. [System.Reflection.BindingFlags]$flags = [System.Reflection.BindingFlags]::Static -bor [System.Reflection.BindingFlags]::NonPublic;  
  11.   
  12. $methodInfo = $reputationHelper.GetMethod("EnableReputation", $flags);  
  13.  
  14. #For enabling Ratings  
  15. $values = @($list, "Ratings", $false);  
  16.  
  17. #OR for enabling Likes  
  18. #$values = @($list, "Likes", $false);  
  19.   
  20. $methodInfo.Invoke($null, @($values));  
  21.  
  22. #For disable Rating or Likes  
  23. <#$methodInfo = $reputationHelper.GetMethod("DisableReputation", $flags);  
  24. $disableValues = @($list);  
  25. $methodInfo.Invoke($null, @($disableValues));#>  
  26. }