Function for Business Data Catalog Service

Feb 17, 2011 at 6:26 PM

This installer script rocks. I needed to setup the Business Data Connectivity Service so I took one of the other service application functions and used it as a template for making this one. One thing that seemed odd to me was that when you create the BCS service application, the proxy was created automatically. But it didn't have the naming I wanted so what I did was to delete the proxy created by default and then create the proxy with the name I wanted. I added a new node to the services section of the configuration file in order to name my database. Hope this helps someone else out.

AutoSPInstallerInput.xml Changes: Add the following under the "Services" node.

 <BusinessDataCatalogServiceApp Provision="True">
   <Database>BDCDataDB</Database>
</BusinessDataCatalogServiceApp>

 

Function:

#Region Create Business Data Catalog Service Application
# ===================================================================================
# Func: CreateBusinessDataCatalogServiceApp
# Desc: Business Data Catalog Service Application
# ===================================================================================
Function CreateBusinessDataCatalogServiceApp([xml]$xmlinput)
{
    If ($($xmlinput.Configuration.Farm.Services.BusinessDataCatalogServiceApp.Provision) -eq $true)
    {
     WriteLine
  try
     {
   $spservice = Get-spserviceaccountxml $xmlinput
            $username = $spservice.username
   $BdcDataDB = $DBPrefix+$xmlinput.Configuration.Farm.Services.BusinessDataCatalogServiceApp.Database
            $FarmAcct = $xmlinput.Configuration.Farm.Account.Username
   Write-Host -ForegroundColor White " - Provisioning Business Data Catalog Service Application"
           # Managed Account
           $ManagedAccountGen = Get-SPManagedAccount | Where-Object {$_.UserName -eq ($username)}
           If ($ManagedAccountGen -eq $NULL) { throw " - Managed Account $username not found" }     
         # App Pool
      Write-Host -ForegroundColor White " - Getting Hosted Services Application Pool, creating if necessary..."
         $ApplicationPool = Get-SPServiceApplicationPool "SharePoint Hosted Services" -ea SilentlyContinue
         if($ApplicationPool -eq $null)
        {
                $ApplicationPool = New-SPServiceApplicationPool "SharePoint Hosted Services" -account $username
                If (-not $?) { throw " - Failed to create an application pool" }
           }   
      Write-Host -ForegroundColor White " - Starting Business Data Catalog Service:"
           
   # Get the service instance
   $BdcServiceInstances = Get-SPServiceInstance | ? {$_.TypeName -eq "Business Data Connectivity Service"}
            $BdcServiceInstance = $BdcServiceInstances | ? {$_.Server.Address -eq $env:COMPUTERNAME}
   If (-not $?) { throw " - Failed to find Business Data Catalog service instance" }
           
   # Start Service instances
   If($BdcServiceInstance.Status -eq "Disabled")
     {
             Write-Host -ForegroundColor White " - Starting Business Data Catalog Service Instance..."
                $BdcServiceInstance.Provision()
                If (-not $?) { throw " - Failed to start Business Data Catalog service instance" }
    # Wait
       Write-Host -ForegroundColor Blue " - Waiting for Business Data Catalog service..." -NoNewline
       While ($BdcServiceInstance.Status -ne "Online")
       {
        Write-Host -ForegroundColor Blue "." -NoNewline
        sleep 1
        $BdcServiceInstances = Get-SPServiceInstance | ? {$_.TypeName -eq "Business Data Connectivity Service"}
     $BdcServiceInstance = $BdcServiceInstances | ? {$_.Server.Address -eq $env:COMPUTERNAME}
       }
       Write-Host -BackgroundColor Blue -ForegroundColor Black ($BdcServiceInstance.Status)
   }
   Else
   {
    Write-Host -ForegroundColor White " - Business Data Catalog Service already started."
   }

          # Create a Business Data Catalog Service Application 
   If ((Get-SPServiceApplication | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.BusinessData.SharedService.BdcServiceApplication"}) -eq $null)
        {     
       # Create Service App
          Write-Host -ForegroundColor White " - Creating Business Data Connectivity Service Application..."   
    $BdcDataServiceApp = New-SPBusinessDataCatalogServiceApplication -Name "Business Data Connectivity Service Application" -ApplicationPool $ApplicationPool -DatabaseServer $DBServer -DatabaseName $BdcDataDB
    If (-not $?) { throw " - Failed to create Business Data Connectivity Service Application" }
    
    # Get the default proxy which was just created and remove it and its data
    Write-Host -ForegroundColor White " - Removing the default service application proxy..."
       $BdcServiceAppProxy = Get-SPServiceApplicationProxy | ? {$_.TypeName -eq "Business Data Connectivity Service Application Proxy"}
       $BdcServiceAppProxyID = $BdcServiceAppProxy.Id
    Write-Host -ForegroundColor White " - Default service application proxy    =$BdcServiceAppProxy"
    Write-Host -ForegroundColor White " - Default service application proxy ID =$BdcServiceAppProxyID"
    Remove-SPServiceApplicationProxy $BdcServiceAppProxyID -RemoveData -Confirm:$false

    # Create new proxy
       Write-Host -ForegroundColor White " - Creating Business Data Connectivity Service Application Proxy..."
                $BdcDataServiceAppProxy  = New-SPBusinessDataCatalogServiceApplicationProxy -Name "Business Data Connectivity Service Application Proxy" -ServiceApplication $BdcDataServiceApp -DefaultProxyGroup
                If (-not $?) { throw " - Failed to create Business Data Connectivity Service Application Proxy" }
           }
        Else
   {
    Write-Host -ForegroundColor White " - Business Data Connectivity Service Application already provisioned."
   }
   Write-Host -ForegroundColor White " - Done creating Business Data Connectivity Service Application."
     }
     catch
     {
      Write-Output $_
     }
    }
 WriteLine
}
#EndRegion

 

 

Coordinator
Feb 22, 2011 at 2:39 AM

Thanks very much for posting this! Another user (rybocf) had posted (among other stuff) a function for creating the BCS service app here:

http://autospinstaller.codeplex.com/discussions/228507?ProjectName=autospinstaller

I plan on having a look at his stuff first and possibly combine your and his for best of both.

Cheers,
Brian

Coordinator
Mar 4, 2011 at 5:32 PM

On second thought, I reviewed your function and was able to integrate it easily with minimal changes - very cool. Will be part of the next release!

Cheers
Brian

Mar 4, 2011 at 10:04 PM
Good to hear. Your project was great so glad I could make a small contribution.

Stephen


brianlala <notifications@codeplex.com> wrote:

>From: brianlala
>
>On second thought, I reviewed your function and was able to integrate it easily with minimal changes - very cool. Will be part of the next release!
>
>Cheers
>Brian
>
>
Mar 10, 2011 at 10:13 AM

Noticed a slight issue with the BDC service not being created in v2 when i ran the installer.

AutoSPInstallerFunctions.ps1 references "$DBPrefix+$($xmlinput.Configuration.ServiceApps.BusinessDataCatalog.Database"

However the corresponding input parameter in AutoSPInstallerInput.xml is set as "BusinessDataConnectivity"

I just changed "BusinessDataConnectivity" to BusinessDataCatalog in the xml file and it installed successfully.

AJ

Coordinator
Mar 10, 2011 at 12:51 PM

Yup thanks I had quickly fixed this in changeset http://autospinstaller.codeplex.com/SourceControl/changeset/changes/69890.

Brian

Aug 19, 2013 at 8:03 PM
Edited Aug 19, 2013 at 8:04 PM
You should update your lines of code with following

$BdcServiceAppProxy = Get-SPServiceApplicationProxy | ? {$_.TypeName -eq "Business Data Connectivity Service Application Proxy" -AND $_.DisplayName -eq "Business Data Connectivity Service Application" }

If you run your command you will get back all proxy groups based on the TypeName "Business Data Connectivity Service Application Proxy". If you use more than one BCS service application you want be happy.

Within SharePoint 2010 / 2013 you know that the proxy group name is the same as the service application what you created before.

Timo
Coordinator
Aug 21, 2013 at 2:16 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.