![]() |
VOOZH | about |
The CData Cmdlets for SharePoint are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SharePoint.
Accessing and integrating live data from SharePoint has never been easier with CData. Customers rely on CData connectivity to:
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.
The Cmdlets are not only a PowerShell interface to SharePoint, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SharePoint data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SharePoint. To access SharePoint data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SharePoint.
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
Install the module:
Install-Module SharePointCmdlets
Connect:
$sharepoint = Connect-SharePoint -User "$User" -Password "$Password" -Auth Scheme "$Auth Scheme" -URL "$URL" -SharePointEdition "$SharePointEdition"
Search for and retrieve data:
$location = "Chapel Hill" $mycustomlist = Select-SharePoint -Connection $sharepoint -Table "MyCustomList" -Where "Location = `'$Location`'" $mycustomlist
You can also use the Invoke-SharePoint cmdlet to execute SQL commands:
$mycustomlist = Invoke-SharePoint -Connection $sharepoint -Query 'SELECT * FROM MyCustomList WHERE Location = @Location' -Params @{'@Location'='Chapel Hill'}
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 -Connection $SharePoint -Columns @('Name','Revenue') -Values @('MyName', 'MyRevenue') -Table MyCustomList -Id "MyId"
$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()
Add-SharePoint -Connection $SharePoint -Table MyCustomList -Columns @("Name", "Revenue") -Values @("MyName", "MyRevenue")
$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()
Remove-SharePoint -Connection $SharePoint -Table "MyCustomList" -Id "MyId"
$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
Download a free trial of the SharePoint Data Provider to get started:
Download NowLearn more:
👁 SharePoint IconProvides .NET developers with the power to easily connect their Web, Desktop, and Mobile applications to data in SharePoint Server Lists, Contacts, Calendar, Links, Tasks, and more!