Posts

Showing posts with the label Powershell

Not able to view result while building Search Query

Image
Hello SharePointers ;), Here is another quick finding which I just thought should be shared to save someone precious time. If you are dealing with SharePoint 2013 search and Result sources, you must try to test the query template before saving it. If you are not able to see any results instead just a red error saying below text don't get scared I have quick solution for you. “The Search display templates are not present on this site collection. To add them, you need to activate the “Search Server Web Parts and Templates” feature on the Site Collection Features page. Display Error: The display template had an error. You can correct it by fixing the template or by changing the display template used in either the Web Part properties or Result Types. Template ‘~sitecollection/_Catalogs/masterpage/DisplayTemplates/System/Control_QueryBuilderPreview.js’ not found or has sytax errors. (Load Template: ) ” You must get frustrated because your search is properly configured, its crawling the ...

SharePoint PowerShell: Upload multiple documents to sharepoint document library

Image
Hi, I was creating a script to replicate document library structure similar to Prod just in order to test the ShareGate Migration. Let me take a brief description about my scenario: Description: There is a document library present on Prod, which contains bulk document (~3000). Now I need to update metadata for all those documents using Excel sheet and ShareGate. I don't have access to the Production library and not even replicate the Library to my Dev environment as it contains some very confidential documents. Solution: I have decided to create a script which will take one template document from file system and read name of document from one of columns of excel. The script will take some time(~hours in case of thousand documents) to upload the template with the new file name. The inputs to the script will be Path of the excel which contains name of documents in one column Path of the file where the template is placed on file system Url of the sharepoint web site Name of th...

Clear SharePoint Config Cache with PowerShell

Hi, In my previous post , I have explained about issue "An update conflict has occurred, and you must re-try this action". That issue occurs because of cache issues. I have already explained the manual way to clear cache. In this blog, I do same thing using the poweshell script. Following code of PowerShell will clear the cache of the server: Add-PSSnapin -Name Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue Stop-Service SPTimerV4 $folders = Get-ChildItem C:\ProgramData\Microsoft\SharePoint\Config foreach ($folder in $folders) { $items = Get-ChildItem $folder.FullName -Recurse foreach ($item in $items) { if ($item.Name.ToLower() -eq "cache.ini") { $cachefolder = $folder.FullName } } } $cachefolderitems = Get-ChildItem $cachefolder -Recurse foreach ($cachefolderitem in $cachefolderitems) { if ($cachefolderitem -like "*.xml") { $cachefolderitem.Delete() } } $a = Get-Content  $cachefolder\cache.ini $a  = 1 Set-Content $a -Path $cachefolder\cache...

SharePoint: An update conflict has occurred, and you must re-try this action

Hi, I have faced this issue while trying to modify list items of a list. This issue encounters if the file system cache content on the SharePoint server is newer than the content present in the configuration database. One have to clear the cache manually to get rid of this issue. Sometimes it get solved by restarting, if luck is with you, otherwise this issue will always bugs. Timer service restart could be one another option to try. But recommend you must follow one of the two possible ways to solve this issue: I. Manual Steps: Need to stop the SharePoint Timer service: Navigate to Start > Administrative Tools >  Services or go to run(Windows+R) command and type  msc . Locate the SharePoint Timer Service , and right click on this service and click on  Stop Close the Services window (In case you are performing these actions on Production/Test. Do this on each front end server) In Windows Explorer, locate and then double-click the following hidden folder. Drive:\ProgramDat...

Migrate SP list from SP 2010 to SP 2013 without using any tool

Image
Hi guys, You might asked to migrate SP list from SP 2010 to SP 2013 environment. This question might be asked that why II now didn't talk about migration of whole site/site collection. Answer is, as there are number of ways one can adopt for migration of whole environment like: 1) Database attache detach(best in case of 2010>2013) 2) Third party tool(best in case of 2007>2013) But in case of second option you might not face this challenge but when doing database detach attach process there are chances that user continued updating old portal and then after some time client released that they need to re-migrate the list to new server again. Any ways don't know real world cases but I got this requirement from client that they want to move four lists from one sub site of old server to new sub site of new server. So I am explaining the way I performed re-migration of list to new server. The solution is quite simple but some tricks to achieve what we want. Find the following s...

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", $fa...

Powershell: Update "Subsite Templates" under AreaTemplateSettings.aspx

Hi, This time I am discussing about how one can update the "AvailableWebTemplates" once you have created a site. Just for the information, we can define this property in Onet.xml while creating any new site. But what if you have created sites, sub sites underneath and sub sub sites underneath, in that case you need a power shell script to update all those values. Background: This property is defined in Onet as shown below: <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416"> ----------------- <Property Key="AvailableWebTemplates" Value="*-CMSPUBLISHING#0;*-BLANKINTERNET#2;*-ENTERWIKI#0;*-SRCHCEN#0"/> --------------------- </Feature> But once site is created using this site template, we have to dig down to update this. Using power shell its quite easy task provided you must know the Id and template name. Work Arround: We using the below mention code we can override the web template property. In order to update that we must know th...