Create crawl rule

28/01/2013 12:43

#Creating crawl rule with specified account (for public site)
$siteUrl="https://server/sitecollection"
$crawlAccount="Cham\testaccount1"
$password = "P@ssWord";

$crawlPath = $siteUrl.Replace("https", "http") + "/*"
$searchapp = Get-SPEnterpriseSearchServiceApplication
# check if crawl rule already exists; if yes: delete
if ((Get-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Identity $crawlPath -ea SilentlyContinue))
{  
 # remove crawl rule; "-confirm:$false" disables confirmation dialog which would otherwise pop up  
 Write-Host "Removing existing crawl rule..."
 Remove-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Identity $crawlPath -confirm:$false
}

$pswd=$password | ConvertTo-SecureString -AsPlainText -Force

Write-Host "Creating crawl rule for $crawlPath..."
$crawlRule = New-SPEnterpriseSearchCrawlRule -SearchApplication $searchapp -Path $crawlPath -Type InclusionRule -CrawlAsHttp 0 -FollowComplexUrls 0 -AuthenticationType "NTLMAccountRuleAccess" -AccountName $crawlAccount -AccountPassword $pswd
$crawlRule.CaseSensitiveURL = 0

$crawlRule.Update()