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"

#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
#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.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *