Powershell: Change Like and comments settings of a library


Hi,

Recently I was working on the requirement to enable the like and comments settings of any library. So I prefer to use PowerShell script for same. I am sharing the code as below:

function Change-SettingsForLikeComment()
{
# Change page library settings for Likes and comments
$list=$web.Lists[“Pages”];
if($list -ne $null)
{
Write-Host $list.Title “not null”;
$assembly=[System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
$reputationHelper =$assembly.GetType(“Microsoft.SharePoint.Portal.ReputationHelper”);

$bindings = @(“EnableReputation”, “NonPublic”, “Static”);
[System.Reflection.BindingFlags]$flags = [System.Reflection.BindingFlags]::Static -bor [System.Reflection.BindingFlags]::NonPublic;

$methodInfo = $reputationHelper.GetMethod(“EnableReputation”, $flags);

#For enabling Ratings
#$values = @($list, “Ratings”, $false);

#OR for enabling Likes
$values = @($list, “Likes”, $false);

$methodInfo.Invoke($null, @($values));

#For disable Rating or Likes
<#$methodInfo = $reputationHelper.GetMethod(“DisableReputation”, $flags);
$disableValues = @($list);
$methodInfo.Invoke($null, @($disableValues));#>
}
}

 

This code will work for Pages library as in most of the cases we prefer to use pages library as a news library. One just have to create a $web object by using the command:

$url= “<url of your sute>“;
$web=Get-SPWeb $url;

and call the method:

Change-SettingsForLikeComment

Thatz it for now. Thanks for time.

Will be back with more scripts!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s