powershellsharepoint-2010

Create SharePoint 2010 search content source that uses a BDC via PowerShell


Using powershell how do you create a content sorce that uses a BDC?

Documentation on Technet for New-SPEnterpriseSearchCrawlContentSource is not very clear on how to do this.

So far this seems most reasonable to me but it doesn't work.

$searchapp = Get-SPEnterpriseSearchServiceApplication "MySearchApplication"
New-SPEnterpriseSearchCrawlContentSource -name "My BDC Content Source" -searchapplication $searchApp -Type Business -LOBSystemSet "NameOfMyBdc"

It creates the content source of type Business Data Connectivity but the specified BDC is not checked off.


Solution

  • This is what worked for me.

    $searchapp = Get-SPEnterpriseSearchServiceApplication "My Search Service Application Name"
    $lobSystems = @("LOBSystemName1","LOBSystemInstanceName1")
    $proxyGroup = Get-SPServiceApplicationProxyGroup -default
    New-SPEnterpriseSearchCrawlContentSource -name "My Content Source Name" -searchapplication $searchApp -Type Business -LOBSystemSet $lobSystems -BDCApplicationProxyGroup $proxyGroup
    

    You can also do it using the API like this. I have no idea what the Guid PartitionId parameter of the ConstructStartAddress method is all about but it doesn't seem to work with any other Guid.

            string strURL = "http://mySiteUrl";
            SearchContext searchContext;
            using (SPSite searchSite = new SPSite(strURL))
            {
                searchContext = SearchContext.GetContext(searchSite);
            }
            Content sspContent = new Content(searchContext);
            ContentSourceCollection sspContentSources = sspContent.ContentSources;
            BusinessDataContentSource bdcs = (BusinessDataContentSource)sspContentSources.Create(typeof(BusinessDataContentSource), "MyBdcContentSource");
            bdcs.StartAddresses.Add(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), "LOBSystemName", "LOBSystemInstanceName"));