Sunday, September 30, 2012

PowerShell HowTo: Create Content Source of Type CustomRepository


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.

CustomRepository

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


Edit Content Source of Type CustomRepository
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.

Scripting

You 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"

Pitfalls

The StartAddresses parameter is not really optional

Don'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:

Error: The custom connector used by the content source has been removed or undeployed.
Figure 2: "The custom connector used by the content source has been removed or undeployed."
The error message hints that the custom protocol used by the indexing connector is not available anymore. This is misleading. The correct error message would be "There are no start addresses provided and I am freaking out about it for no reason.".

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 part

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

No comments:

Post a Comment