Monday, 25 December 2017

PowerShell: Assign permission to read-only users on the list on all site levels.


#
# Description:
# List-Level Permission settings and assign "Contribute" role definition to the visitors group.
# To allow read-only users to post, update, delete comments.
#
# Created Date:
# v1.0 - 07-12-2017
#
# Author:
# Vikas Bansal
#
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$listName = "TestList"
#get all webs (sub-sites) under site collection
$WebsColl = Get-SPSite https://sp2013.com | Get-SPWeb -Limit ALL
#iterate through each sub-site change list permissions
foreach($web in $WebsColl) {
$commentsList = $web.Lists.TryGetList($listName)
if($commentsList -ne $null)
{
Write-Host $listName " exists on the" $web.Title at URL $web.Url -ForegroundColor DarkBlue -BackgroundColor Yellow
# Assign the "Contribute" RoleDefinition to the site's visitors group
$visitorsSPGroup = $commentsList.ParentWeb.AssociatedVisitorGroup #$spWeb.Groups[$visitorsSPGroupName]
if(!$commentsList.HasUniqueRoleAssignments) {
$commentsList.BreakRoleInheritance($true)
}
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($visitorsSPGroup)
$assignment.RoleDefinitionBindings.Add(($commentsList.ParentWeb.RoleDefinitions | Where-Object { $_.Type -eq "Contributor" }))
$commentsList.RoleAssignments.Add($assignment)
$commentsList.Update()
Write-Host $listName " permission is changed for readonly users on the" $web.Title at URL $web.Url -ForegroundColor DarkGreen -BackgroundColor White
}
else
{
Write-Host $listName " not exists on the" $web.Title at URL $web.Url -ForegroundColor Yellow -BackgroundColor Red
}
}


PowerShell: Activate feature on all site levels.


#
# Description:
# Activate the site feature on all sub-sites
# This feature creates custom list
#
# Created Date:
# v1.0 - 27-11-2017
#
# Author:
# Vikas Bansal
#
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#feature ID to create custom list
$FeatureID="3e0d7f50-a6b7-45a6-b5a1-77950ef4327f"
#get all webs (sub-sites) under site collection
$WebsColl = Get-SPSite https://sp2013.com | Get-SPWeb -Limit ALL
#get the Feature
$Feature = Get-SPFeature -Limit All | Where { $_.ID -eq $FeatureID }
#check if Feature exists
if($Feature -ne $null) {
Write-Host "feature exists" -ForegroundColor DarkBlue -BackgroundColor Yellow
#iterate through through each sub-site activate the feature
foreach($web in $WebsColl){
#check if the Feature is activated
if (Get-SPFeature -web $web.Url | Where {$_.ID -eq $FeatureId}) {
Write-Host "feature is already activated on " $web.Url -ForegroundColor DarkBlue -BackgroundColor Yellow
}
else {
Write-Host "feature not activated on " $web.Url -ForegroundColor Yellow -BackgroundColor Red
#Activate the Feature
Enable-SPFeature –identity $FeatureID -URL $web.URL -Confirm:$false
Write-Host "feature is activated now on " $web.Url -ForegroundColor DarkBlue -BackgroundColor White
}
}
}
else {
Write-Host "feature does not exists" -ForegroundColor Yellow -BackgroundColor Red
}


Sunday, 7 May 2017

SharePoint search query length error.

SharePoint 2013 search results query works properly if select, filter, and other options are in the search query text limit. If the search query limit exceeds the search results, it gives an error.

"An administrator configuration transformed your query into an invalid query"


The search length (in KB) is controlled by the property MaxKeywordQueryTextLength of the SharePoint search service application. The default "MaxKeywordQueryTextLength" value is 4096 (4 KB). Use the PowerShell commands given below.




So increasing the MaxKeywordQueryTextLength value from 4 KB to 8 KB helped in fixing the error.

The reference blog: https://blogs.msdn.microsoft.com/sridhara/2014/05/06/sharepoint-2013-searchserviceexception-the-maximum-allowed-value-is-4096/


🚀 "Happy Coding" 🚀