SharePoint 2013 and PowerShell–Retrieving BCS List Items

2017-12-11T10:16:00+00:00 June 3rd, 2013|PowerShell, Sharepoint|

A colleague and I were recently looking at  synchronising two Lists. One of the Lists was a BCS List and when attempting to connect via PowerShell using the normal methods, it failed and returned the following error:

The shim execution failed unexpectedly – Proxy creation failed. Default context not found

Proxy Error

I’ve trimmed the whole script down to keep things relevant for this post, but let’s look at the failing component:

 $webApplicationURL = "http://sharepoint"
 $BCSList = "CRM Data"
 $web = Get-SPWeb $webApplicationURL
 $list = $web.Lists[$BCSList]
 foreach ($item in $list.Items)
 {
 $Name = $item["Name"]
 }

The problem is being caused by a lack of ServiceContext. Let’s declare it before importing the “WSDL BCS Catalog” and it should now be working as expected:

 $webApplicationURL = "http://sharepoint"
 $BCSList = "CRM Data"
 $context = Get-SPServiceContext $webApplicationURL
 $scope = new-object Microsoft.SharePoint.SPServiceContextScope $context
 $web = Get-SPWeb $webApplicationURL
 $list = $web.Lists[$BCSList]
 foreach ($item in $list.Items)
 {
 $Name = $item["Name"]
 }

For full details about this message from Microsoft Support, head over to http://support.microsoft.com/kb/983018