Setting up the project environment
Before starting with the coding, two additional libraries have to be loaded:
To access useful Cmdlets that help us to manipulate SharePoint Objects from PowerShell it is necessary to add the Microsoft.SharePoint.PowerShell Snapin into our Script. This Snapin can be added as follow:
Once added and the script is executed the Snapin will be loaded into the current PowerShell session.
We need this library in order to use the BusinessDataListConnector API. To load it into the script it is necessary to use the Add-Type Cmdlet (this Cmdlet adds a Microsoft .NET Framework Type to the current PowerShell session).
The library can be added as follow:
[string]$currentScriptDirectory = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
Add-Type -Path (Join-Path $currentScriptDirectory "Layer2.SharePoint.BusinessDataListConnector.dll")
The Layer2.SharePoint.BusinessDataListConnector.dll DLL has to be placed in the same directory as the current script.
Getting the SharePoint Web & List
Since we are using the Microsoft.SharePoint.PowerShell Snapin we will work with the SharePoint SSOM. Through SSOM we can get the List and the Web where the list is located as follow:
$site = Get-SPSite -Identity "https://site.sp2013"
$web = $site.RootWeb
$list = $web.Lists.TryGetList("BDLC_TestList")
Once this is done we can proceed to start using the API.