Automate SharePoint Integration Tasks from PowerShell
The CData ADO.NET Provider for SharePoint is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SharePoint.
About SharePoint Data Integration
Accessing and integrating live data from SharePoint has never been easier with CData. Customers rely on CData connectivity to:
- Access data from a wide range of SharePoint versions, including Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007 and above, and SharePoint Online.
- Access all of SharePoint thanks to support for Hidden and Lookup columns.
- Recursively scan folders to create a relational model of all SharePoint data.
- Use SQL stored procedures to upload and download documents and attachments.
Most customers rely on CData solutions to integrate SharePoint data into their database or data warehouse, while others integrate their SharePoint data with preferred data tools, like Power BI, Tableau, or Excel.
For more information on how customers are solving problems with CData's SharePoint solutions, refer to our blog: Drivers in Focus: Collaboration Tools.
Getting Started
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for SharePoint; this tutorial shows how to use the Provider to create, retrieve, update, and delete SharePoint data.
Once you have acquired the necessary connection properties, accessing SharePoint data in PowerShell can be enabled in three steps.
Set the URL property to the base SharePoint site or to a sub-site. This allows you to query any lists and other SharePoint entities defined for the site or sub-site.
The User and Password properties, under the Authentication section, must be set to valid SharePoint user credentials when using SharePoint On-Premise.
If you are connecting to SharePoint Online, set the SharePointEdition to SHAREPOINTONLINE along with the User and Password connection string properties. For more details on connecting to SharePoint Online, see the "Getting Started" chapter of the help documentation
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SharePoint\lib\System.Data.CData.SharePoint.dll") -
Connect to SharePoint:
$conn= New-Object System.Data.CData.SharePoint.SharePointConnection("User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise;") $conn.Open() -
Instantiate the SharePointDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, Revenue from MyCustomList" $da= New-Object System.Data.CData.SharePoint.SharePointDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.revenue }
Update SharePoint Data
$cmd = New-Object System.Data.CData.SharePoint.SharePointCommand("UPDATE MyCustomList SET Location='Chapel Hill' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SharePoint.SharePointParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert SharePoint Data
$cmd = New-Object System.Data.CData.SharePoint.SharePointCommand("INSERT INTO MyCustomList (Location) VALUES (@myLocation)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SharePoint.SharePointParameter("@myLocation","Chapel Hill")))
$cmd.ExecuteNonQuery()
Delete SharePoint Data
$cmd = New-Object System.Data.CData.SharePoint.SharePointCommand("DELETE FROM MyCustomList WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SharePoint.SharePointParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject