Pages

Search This Blog

Monday, November 28, 2011

Configuring crawl schedules using powershell scripts:SharePoint 2010


Quite often, we come across a requirement wherein we need to automate some tasks like configuring search crawl schedules.

We can do it through the UI , but an automated powershell script always comes in handy and saves time.

Following is the powershell script to create both full crawl and incremental crawl schedules for a content source in sharepoint 2010.


Add-PsSnapin Microsoft.SharePoint.PowerShell
Write-Host 'Configuring full crawl and incremental crawl....'

$searchServiceAppName =”Search Service Application 1”

$searchContext=[Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($searchServiceAppName)

Write-Host 'Configuring full crawl settings....'

$fullCrawlSchedule=New-Object Microsoft.Office.Server.Search.Administration.DailySchedule($searchContext)

$fullCrawlSchedule.BeginDay='30'

$fullCrawlSchedule.BeginMonth='11'

$fullCrawlSchedule.BeginYear='2011'

$fullCrawlSchedule.StartHour='1'

$fullCrawlSchedule.StartMinute='30'

$fullCrawlSchedule.DaysInterval='1'

Write-Host 'Configuring Incremental crawl settings....'
$incrementalCrawlSchedule=New-Object Microsoft.Office.Server.Search.Administration.DailySchedule($searchContext)

$incrementalCrawlSchedule.BeginDay='30'

$incrementalCrawlSchedule.BeginMonth='11'

$incrementalCrawlSchedule.BeginYear='2011'

$incrementalCrawlSchedule.StartHour='1'

$incrementalCrawlSchedule.StartMinute='30'

$incrementalCrawlSchedule.DaysInterval='1'

$incrementalCrawlSchedule.RepeatInterval='10'

$incrementalCrawlSchedule.RepeatDuration='1440'

Write-Host 'Creating schedules for content source ...'

$contentSource=Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchServiceAppName -Identity “Local SharePoint Sites”

$contentSource.IncrementalCrawlSchedule=$incrementalCrawlSchedule

$contentSource.FullCrawlSchedule=$fullCrawlSchedule

$contentSource.Update()

Write-Host 'Full Crawl and incremental crawl schedules configured successfully.'

Once this script is run, we can see the crawl schedules configured for the content source in the search service application:




No comments:

Post a Comment