Add New Content Source in SharePoint Search using PowerShell
Requirement: Create a new search content source in SharePoint 2013 / 2016.
PowerShell script to add new content source:
Here is the PowerShell script to create a new content source in the SharePoint search.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
#Variables for new content source creation
$ContentSourceName= "Intranet Portal" #default "Local SharePoint sites"
$ContentSourceType="SharePoint"
$ContnetSourceURL="https://portal.crescent.com"
#Get the search service application
$SSA = Get-SPEnterpriseSearchServiceApplication #-Identity "Search Service Application Name"
#Check if the given content source Name exits already
$ContentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA | where {$_.Name -eq $ContentSourceName}
if ($ContentSource)
{
write-host "Content Source Name already exist!" -f Red
exit
}
#Create new content source
$ContentSource = New-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA -Type $ContentSourceType `
-name $ContentSourceName -StartAddresses $ContnetSourceURL -MaxSiteEnumerationDepth 0
write-host "New Content Source has been created!" -f Green
#To delete a content source, use:
#Remove-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA -Identity $ContentSourceNames
You must run full crawl for any new content source created. Here is how: How to Start SharePoint Search Crawl using PowerShell
New-SPEnterpriseSearchCrawlContentSource reference in Technet.