How To: Configure SharePoint 2010 BCS connection information with PowerShell

One of the most common things you’d want to change is connection information for your LOBSystem. There is no SharePoint out-of-the-box UI for it, but thankfully PowerShell can access and change BCS LOB System connection configuration.
Page Content

 

If you worked with BCS in SharePoint 2010 you know that you can configure your BCS models and connection information right in the model configuration file, and that’s something developers will create for you. But once your model has been deployed to the server – all of the configuration information stays there. Some of the model details you can change using SharePoint Designer, some others you just can’t get to.

One of the most common things you’d want to change is connection information for your LOBSystem. There is no SharePoint out-of-the-box UI for it, but thankfully PowerShell can access and change BCS LOB System connection configuration.

Just so we’re on the same page, I assume you already have BCS model installed in your farm. Let’s assume your BCS system instance (LobSystemInstance) has the name of My.Project.BCSInstance; this is important to change in the commands below.

To get your LobSystemInstance value, also used in the script below, navigate to Central Administration -> Manage Service Applications -> click Business Data Connectivity Service -> switch the view to External Systems

2011-12-20-SP2010BCSConnections-01.png

In the same screen you will find your External System Name (in our case it’s My.Project.BCSSystem).

To find out External System Instance Name (in my case My.Project.BCSInstance), click on the BCS system name from the screen above and grab a value of External System Instance Name

Also, I assume you’re connecting to a SQLServer machine with the machine name of MySqlserver, you can also change that in the script below.

Open SharePoint 2010 Management Shell and execute the following script, substituting variables with your own.

01 $lob = Get-SPBusinessDataCatalogMetadataObject
02   -BdcObjectType "LobSystem"
03   -Name "My.Project.BCSSystem"
04   -ServiceContext "http://[site URL]"
05
06 $instance = $lob.LobSystemInstances | Where-Object {$_.Name -eq "My.Project.BCSInstance"}
07
08 Set-SPBusinessDataCatalogMetadataObject –Identity $instance
09   –PropertyName "AuthenticationMode" –PropertyValue "PassThrough"
10
11 Set-SPBusinessDataCatalogMetadataObject –Identity $instance
12   –PropertyName "RdbConnection Data Source" –PropertyValue "MySqlserver"
13
14 Set-SPBusinessDataCatalogMetadataObject –Identity $instance
15   –PropertyName "RdbConnection User ID" –PropertyValue "My.Sql.User"
16
17 Set-SPBusinessDataCatalogMetadataObject –Identity $instance
18   –PropertyName "RdbConnection Password" –PropertyValue "MyPassword#!"
19
20 Set-SPBusinessDataCatalogMetadataObject –Identity $instance
21   –PropertyName "RdbConnection Integrated Security" –PropertyValue " "
22
23 $instance.Update()
24 $lob.Update()

That’s it – the script above will connect to the BCS system instance and change any provisioned variables with the ones in the script.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: