Posts Tagged ‘Powershell’

SharePoint 2013: Identifying the variation source and target with PowerShell

While working with one reporting requirement I needed to eliminate the variation targets and only need to consider variation sources. I struggled to find out the property which will help me to identify the page is variation source or target.


Publishing web and Publishing page have the property called as ‘PublishingPage.Label.IsSource’ which we can use to identify the source page and source web. The same way we can use the publishing web level property as well.

if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($childWeb)){
 $spPubWeb =

 $item = $spPubWeb.PagesList.GetItemById($row.ID);
 $pubPage =

 if($pubPage.VariationPageUrls.Count -eq 0)
     #Page directly created in language sites and not Variated from source
 else #Page Variated
   if($pubPage.Label.IsSource) # then check if the web is Label IsSource
     #this page is variation source

Hope this will help, happy learning.

SharePoint 2013: Exception while creating default associated groups through PowerShell

While new site collection provisioned default security groups been provisioned when we create it from central administration but not when the site collection was created using script. For that we need to call a function ‘CreateDefaultAssociatedGroups’. This method actually created default associated group example member, Owner and Visitor group and add the group owner as the first parameter provided to the method call.

When I tried it some cases it worked and in some cases I was getting error “Exception calling “CreateDefaultAssociatedGroups” with “3” argument(s): “User cannot be found”

While analyzing the issue the issue I found that I am passing only first mandatory parameter as the user logon name of the group owner. Like –


And then I was getting error Exception calling “CreateDefaultAssociatedGroups” with “3” argument(s): “User cannot be found.” And the default groups are not getting added.

Further analysis concluded that the user I was passing as group owner was not getting added and hence the exception is thrown.

We have used EnsureUser before calling CreateDefaultAssociatedGroups function to make sure that before the call user should be available in user information list like –


Enable Rating or Likes Settings in SharePoint 2013

June 19, 2013 7 comments

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

$web=Get-SPWeb "";
if($list -ne $null)
 Write-Host $list.Title "not null";
 $assembly=[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=, 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));#>