Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: How to Manage Search in SharePoint 2013 with Powershell
In this article I will show you How to Manage Search in SharePoint 2013 with Powershell. When you are operating with enterprise search at the farm level, moving configuration changes across development, staging, and production environments will become tedious. For my current project, I actually have an outsized quantity of managed properties, a couple of crawl rules and result sources. To alter deployments, i made a decision to automate the configuration changes through PowerShell scripts. as luck would have it there were a bunch of scripts already offered on the online that got me most of the manner. I started with those and additional increased them via XML configuration files to urge the subsequent scripts. The PowerShell and XML configuration files may be found here in our GitHub repository.
CreateCrawlRules.ps1
This scripts creates inclusion/exclusion crawl rules with relevant properties.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
[CmdletBinding()] Param( [Parameter(Mandatory=$True,Position=1)] [string]$fileName ) #http://sharepointbrainpump.blogspot.com/2012/10/powershell-howo-creating-and-deleting-crawl-rules.html Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue write-host "Parsing file: " $fileName $XmlDoc = [xml](Get-Content $fileName) #Search Service Application $sa = $XmlDoc.SearchProperties.ServiceName $searchapp = Get-SPEnterpriseSearchServiceApplication $sa #Process Rules $RuleNodeList = $XmlDoc.CrawlRules.Rules foreach ($XmlRule in $RuleNodeList.Rule) { $path = $XmlRule.InnerText if ((Get-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Identity $path -EA SilentlyContinue)) { #Remove Existing Rule Write-Host "Rule Removed: " $path Remove-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Identity $path -confirm:$false } #Create Rule & Properties $complexUrls = [System.Convert]::ToBoolean($XmlRule.FollowComplexUrls) $regExp = [System.Convert]::ToBoolean($XmlRule.RegularExpression) New-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Path $path -Type $XmlRule.Type -IsAdvancedRegularExpression $regExp -FollowComplexUrls $complexUrls $Rule = Get-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Identity $path -EA SilentlyContinue if($XmlRule.Type -eq "InclusionRule") { #Update additional properties for inclusion rules $Rule.CrawlAsHttp = [System.Convert]::ToBoolean($XmlRule.CrawlAsHttp) $Rule.SuppressIndexing = [System.Convert]::ToBoolean($XmlRule.SuppressIndexing) $Rule.Update() } } |
CreateResultSources.ps1
This script creates managed result sources with the appropriate name, sorting and query.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
[CmdletBinding()] Param( [Parameter(Mandatory=$True,Position=1)] [string]$fileName, [Parameter(Mandatory=$True,Position=2)] [string]$siteUrl ) Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue # load Search assembly [void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search") write-host "Parsing file: " $fileName $XmlDoc = [xml](Get-Content $fileName) #Search Service Application $sa = $XmlDoc.SearchProperties.ServiceName $searchapp = Get-SPEnterpriseSearchServiceApplication $sa #Any site connected to the search application $site = get-spsite $siteUrl # create manager instances $fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($searchapp) $searchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa, $site.RootWeb) #process sources $SourcesList = $XmlDoc.SearchSources.Sources foreach ($SourceNode in $SourcesList.Source) { $resultSource = $fedManager.GetSourceByName($SourceNode.Name, $searchOwner) if($resultSource -ne $null) { #Remove existing source Write-Host "Source Removed: " $resultSource.Name $fedManager.RemoveSource($resultSource) } $query = $SourceNode.InnerText $queryProperties = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties #prepare sorting if($SourceNode.SortField -ne "") { $sortCollection = New-Object Microsoft.Office.Server.Search.Query.SortCollection $sortDirection = [Microsoft.Office.Server.Search.Query.SortDirection]::Ascending if($SourceNode.SortDirection -eq "Descending") { $sortDirection = [Microsoft.Office.Server.Search.Query.SortDirection]::Descending } $sortCollection.Add($SourceNode.SortField, $sortDirection) $queryProperties["SortList"] = [Microsoft.Office.Server.Search.Query.SortCollection]$sortCollection } #Create source $resultSource = $fedManager.CreateSource($searchOwner) $resultSource.Name = $SourceNode.Name $resultSource.ProviderId = $fedManager.ListProviders()[$SourceNode.Provider].Id $resultSource.CreateQueryTransform($queryProperties, $query) $resultSource.Commit() } |
CreateSchemaProperties.ps1
The code below will create metadata crawled properties, metadata managed properties, and property mappings. It can also be used to update mappings for OOTB properties.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
[CmdletBinding()] Param( [Parameter(Mandatory=$True,Position=1)] [string]$fileName ) Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue write-host "Parsing file: " $fileName $XmlDoc = [xml](Get-Content $fileName) #Search Service Application $sa = $XmlDoc.SearchProperties.ServiceName $searchapp = Get-SPEnterpriseSearchServiceApplication $sa #process crawled properties $CrawledPropNodeList = $XmlDoc.SearchProperties.CrawledProperties foreach ($CrawledPropNode in $CrawledPropNodeList.CrawledProperty) { #create crawled property if it doesn't exist if (!(Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Name $CrawledPropNode.Name -ea "silentlycontinue")) { $varType = 0 switch ($CrawledPropNode.Type) { "Text" { $varType=31 } "Integer" { $varType=20 } "Decimal" { $varType=5 } "DateTime" { $varType=64 } "YesNo" { $varType=11 } default { $varType=31 } } $crawlprop = New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category SharePoint -VariantType $varType -Name $CrawledPropNode.Name -IsNameEnum $false -PropSet "00130329-0000-0130-c000-000000131346" } } #process managed properties $PropertyNodeList = $XmlDoc.SearchProperties.ManagedProperties foreach ($PropertyNode in $PropertyNodeList.ManagedProperty) { $SharePointPropMapList = $PropertyNode.Map $recreate = [System.Convert]::ToBoolean($PropertyNode.Recreate) if ($recreate) { #Delete if property should be recreated and it exists if($mp = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $PropertyNode.Name -ea "silentlycontinue") { Write-Host "Managed Property Removed: " $PropertyNode.Name $mp.DeleteAllMappings() $mp.Delete() $searchapp.Update() } #create managed property New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $PropertyNode.Name -Type $PropertyNode.Type } if($mp = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $PropertyNode.Name) { if($recreate) { #set configuration for new property $mp.RespectPriority = [System.Convert]::ToBoolean($PropertyNode.RespectPriority) $mp.Searchable = [System.Convert]::ToBoolean($PropertyNode.Searchable) $mp.Queryable = [System.Convert]::ToBoolean($PropertyNode.Queryable) $mp.Retrievable = [System.Convert]::ToBoolean($PropertyNode.Retrievable) $mp.HasMultipleValues = [System.Convert]::ToBoolean($PropertyNode.HasMultiple) $mp.Refinable = [System.Convert]::ToBoolean($PropertyNode.Refinable) $mp.Sortable = [System.Convert]::ToBoolean($PropertyNode.Sortable) $mp.Update() } #add property mappings foreach ($SharePointPropMap in $SharePointPropMapList) { $cat = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $searchapp -Identity $SharePointPropMap.Category $prop = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Name $SharePointPropMap.InnerText New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -CrawledProperty $prop -ManagedProperty $mp } } } |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options
Print article | This entry was posted by Peter on February 25, 2015 at 3:57 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |