![]() |
VOOZH | about |
The CData Cmdlets for Microsoft Dataverse 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 Microsoft Dataverse.
CData provides the easiest way to access and integrate live data from Microsoft Dataverse (formerly the Common Data Service). Customers use CData connectivity to:
CData customers use our Dataverse connectivity solutions for a variety of reasons, whether they're looking to replicate their data into a data warehouse (alongside other data sources)or analyze live Dataverse data from their preferred data tools inside the Microsoft ecosystem (Power BI, Excel, etc.) or with external tools (Tableau, Looker, etc.).
The Cmdlets are not only a PowerShell interface to Microsoft Dataverse, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Microsoft Dataverse data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Microsoft Dataverse. To access Microsoft Dataverse data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Microsoft Dataverse.
Once you have acquired the necessary connection properties, accessing Microsoft Dataverse data in PowerShell can be enabled in three steps.
You can connect without setting any connection properties for your user credentials. Below are the minimum connection properties required to connect.
When you connect the Common Data Service OAuth endpoint opens in your default browser. Log in and grant permissions. The OAuth process completes automatically.
Install the module:
Install-Module CDSCmdlets
Connect:
$cds = Connect-CDS -OrganizationUrl "$OrganizationUrl" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$name = "MyAccount" $accounts = Select-CDS -Connection $cds -Table "Accounts" -Where "Name = `'$Name`'" $accounts
You can also use the Invoke-CDS cmdlet to execute SQL commands:
$accounts = Invoke-CDS -Connection $cds -Query 'SELECT * FROM Accounts WHERE Name = @Name' -Params @{'@Name'='MyAccount'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Microsoft Dataverse\lib\System.Data.CData.CDS.dll")
Connect to Microsoft Dataverse:
$conn= New-Object System.Data.CData.CDS.CDSConnection("OrganizationUrl=https://myaccount.crm.dynamics.com/;InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the CDSDataAdapter, execute an SQL query, and output the results:
$sql="SELECT AccountId, Name from Accounts"
$da= New-Object System.Data.CData.CDS.CDSDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.accountid $_.name
}
Update-CDS -Connection $CDS -Columns @('AccountId','Name') -Values @('MyAccountId', 'MyName') -Table Accounts -Id "MyId"
$cmd = New-Object System.Data.CData.CDS.CDSCommand("UPDATE Accounts SET Name='MyAccount' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.CDS.CDSParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-CDS -Connection $CDS -Table Accounts -Columns @("AccountId", "Name") -Values @("MyAccountId", "MyName")
$cmd = New-Object System.Data.CData.CDS.CDSCommand("INSERT INTO Accounts (Name) VALUES (@myName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.CDS.CDSParameter("@myName","MyAccount")))
$cmd.ExecuteNonQuery()
Remove-CDS -Connection $CDS -Table "Accounts" -Id "MyId"
$cmd = New-Object System.Data.CData.CDS.CDSCommand("DELETE FROM Accounts WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.CDS.CDSParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Microsoft Dataverse Data Provider to get started:
Download NowLearn more:
👁 Microsoft Dataverse IconRapidly create and deploy powerful .NET applications that integrate with Microsoft Dataverse.