In this post I explain how to create a SharePoint content source of type CustomRepository via PowerShell. There are some pitfalls which I will highlight.
CustomRepositoryContent sources of type CustomRepository are used to index external data sources which aren't supported by any of the built-in indexing connectors. These content sources are to be used in conjunction with Custom Indexing Connectors, which use a custom protocol to access the external system.
The property page of an already created content source of type CustomRepository looks like in Figure 1.
|Figure 1: Content source; properties relating to type CustomRepository are highlighted|
You can see that a custom connector named Custom Protocol with scheme protocol1 is used to access the external system. How to register the custom connector will be topic of another blog post.
ScriptingYou can use PowerShell to script the creation of this type of content source. It is pretty straightforward if you know about the pitfalls.
Use the New-SPEnterpriseSearchCrawlContentSource cmdlet. Here is a working example:
$contentSource = New-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa -Type CustomRepository -Name "My Content Source" -CustomProtocol "protocol1" -StartAddresses "protocol1://localhost"
The StartAddresses parameter is not really optionalDon't forget to specify the StartAddresses parameter! The cmdlet's documentation states that this parameter is optional. Well, this is true in the sense of skipping this parameter won't stop the content source from being created. But it will be broken:
|Figure 2: "The custom connector used by the content source has been removed or undeployed."|
There is also no way to correct this. The radio box next to Custom Protocol cannot be clicked and the OK button of the dialog is disabled. And won't be enabled again. The only way to fix the content source is to delete it.
So remember to provide a start address when creating a content source via cmdlet.
Don't use start addresses with empty host partUsing a start address like "protocol1://" (with empty host part) can also lead to the above error. I say "can" because this sometimes seemed to work, sometime not.
So to be sure you should always specify a host in your start address.