Creating a Search Content Source of type Web using PowerShell

The New-SPEnterpriseSearchCrawlContentSource command in Powershell is used to create a new crawl content source for a SharePoint search application.We can view the whole set of parameters and options in this msdn article.

So , when we need to create a SharePoint Search content source, using Powershell, we use the following commands-

[sourcecode language="xml"]
$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
New-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchapp -Type SharePoint -name ContentSourceWithTypeSharePoint -StartAddresses http://localhost:6001/
[/sourcecode]

This would create a content source

Clicking on the “ContentSourceWithTypeSharePoint” would open up the content source which we have created using the default settings as below:

This was a simple scenario. Now consider creating the content source of type “Web” which would be

[sourcecode language="xml"]
$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
New-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchapp -Type Web -name ContentSourceWithTypeWeb -StartAddresses http://localhost:5000/
[/sourcecode]

And this would create a content source with type “Web” as below

Here, we can see that the crawl behavior is set to custom and there would be no direct parameters in Powershell to change these options.

So, I recently had a research into this and found out that adding the parameters, MaxPageEnumerationDepth and MaxSiteEnumerationDepth , could bring you these options.

ie, To bring the crawl option to the second option -”

[sourcecode language="xml"]
$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
New-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchapp -Type Web -name ContentSourceWithTypeWeb -StartAddresses http://localhost:5000/ -MaxPageEnumerationDepth 0 -MaxSiteEnumerationDepth 0
[/sourcecode]

This actually means that the Page depth and the Site depth that you expect is zero, which defaultly means that you would be crawling only the first page of your start address and hence this option is selected.

and to bring the crawl option to the first option -”

[sourcecode language="xml"]
$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
New-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchapp -Type Web -name ContentSourceWithTypeWeb -StartAddresses http://localhost:5000/ -MaxSiteEnumerationDepth 0
[/sourcecode]

This actually means that the Site depth that you expect is zero and it can go any pages deep if it is within the server, which definitely means you would be crawling only within the server of the start address.

This post was inspired from a question asked in SharePoint.Stackexchange.com - http://sharepoint.stackexchange.com/questions/27901/how-to-create-a-content-source-of-type-web-with-the-option-only-crawl-within/27908#27908

About Deepu Nair

Currently working as Technical Lead in SharePoint for Ernst and Young in Kerala, Technopark. He has been enjoying SharePoint since 2007 . He is also MCTS certified for MOSS and SharePoint 2010. You can follow him in Twitter - @deepuvnair

2 thoughts on “Creating a Search Content Source of type Web using PowerShell

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>