Export Search Service Application Crawler Settings to PowerShell in SharePoint 2010

If you ever wanted to take a snapshot of your search service application crawler settings in SharePoint 2010 then you already know that there’s no easy way of doing it without writing custom code. Even if you initially deployed crawler settings to your SharePoint farm using PowerShell scripts, chances are that some settings have been updated manually and the current configuration no longer matches the original deployment scripts. The following PowerShell script exports the main properties of Content Sources, Crawl Rules and Server Name Mappings that exist within a search service application. It’s not complete by any means but can serve as a starting point to be customized and extended to match your specific requirements. One thing to highlight is that the script doesn’t simply export the current search crawler settings to a data file but it actually translates your configuration into PowerShell commands that can later be executed to restore crawler settings to the current state.

$ssaName = "FASTContent"
$searchApp = Get-SPEnterpriseSearchServiceApplication $ssaName

$filePath = "ContentSourcesExport.ps1"
"`$searchApp = Get-SPEnterpriseSearchServiceApplication `"$ssaName`"" | Out-File $filePath
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchApp | Foreach-Object {"New-SPEnterpriseSearchCrawlContentSource -SearchApplication `$searchApp -Name `"" + $_.Name + "`" -Type " + $_.Type + " -StartAddresses `"" + [System.String]::Join(",",$_.StartAddresses) + "`""} | Out-File $filePath -Append

$filePath = "CrawlRulesExport.ps1"
"`$searchApp = Get-SPEnterpriseSearchServiceApplication `"$ssaName`"" | Out-File $filePath
Get-SPEnterpriseSearchCrawlRule -SearchApplication $searchApp | Foreach-Object {"New-SPEnterpriseSearchCrawlRule -SearchApplication `$searchApp –Path `"" + $_.Path + "`" –CrawlAsHttp `$" + $_.CrawlAsHttp + " -Type " + $_.Type + " -FollowComplexUrls `$" + $_.FollowComplexUrls} | Out-File $filePath -Append

$filePath = "ServerNameMappingsExport.ps1"
"`$searchApp = Get-SPEnterpriseSearchServiceApplication `"$ssaName`"" | Out-File $filePath
Get-SPEnterpriseSearchCrawlMapping -SearchApplication $searchApp | Foreach-Object {"New-SPEnterpriseSearchCrawlMapping -SearchApplication `$searchApp -Url `"" + $_.Source + "`" -Target `"" + $_.Target + "`""} | Out-File $filePath -Append

The script below can be used to easily delete all of Content Sources, Crawl Rules and Server Name Mappings that exist within a given search service application.

$ssaName = "FASTContent"
$searchApp = Get-SPEnterpriseSearchServiceApplication $ssaName

Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchApp | Remove-SPEnterpriseSearchCrawlContentSource

Get-SPEnterpriseSearchCrawlRule -SearchApplication $searchApp | Remove-SPEnterpriseSearchCrawlRule

Get-SPEnterpriseSearchCrawlMapping -SearchApplication $searchApp | Remove-SPEnterpriseSearchCrawlMapping
  • pritinp

    This is great stuff!

  • Eric Fang

    Nice scripts! Thanks!