Automate Microsoft Dataverse Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Are you in search of a quick and easy way to access Microsoft Dataverse data from PowerShell? This article demonstrates how to utilize the Microsoft Dataverse Cmdlets for tasks like connecting to Microsoft Dataverse data, automating operations, downloading data, and more.

The CData ADO.NET Provider for Microsoft Dataverse 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 Microsoft Dataverse.

About Microsoft Dataverse Data Integration

CData provides the easiest way to access and integrate live data from Microsoft Dataverse (formerly the Common Data Service). Customers use CData connectivity to:

  • Access both Dataverse Entities and Dataverse system tables to work with exactly the data they need.
  • Authenticate securely with Microsoft Dataverse in a variety of ways, including Microsoft Entra ID, Azure Managed Service Identity credentials, and Azure Service Principal using either a client secret or a certificate.
  • Use SQL stored procedures to manage Microsoft Dataverse entities - listing, creating, and removing associations between entities.

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.).


Getting Started


ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Microsoft Dataverse; this tutorial shows how to use the Provider to create, retrieve, update, and delete Microsoft Dataverse data.

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.

  • InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • OrganizationUrl: Set this to the organization URL you are connecting to, such as https://myorganization.crm.dynamics.com.
  • Tenant (optional): Set this if you wish to authenticate to a different tenant than your default. This is required to work with an organization not on your default Tenant.

When you connect the Common Data Service OAuth endpoint opens in your default browser. Log in and grant permissions. The OAuth process completes automatically.

  1. 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")
        
  2. Connect to Microsoft Dataverse:

     
    $conn= New-Object System.Data.CData.CDS.CDSConnection("OrganizationUrl=https://myaccount.crm.dynamics.com/;InitiateOAuth=GETANDREFRESH;")
    $conn.Open()
    
  3. 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 Microsoft Dataverse Data


$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()

Insert Microsoft Dataverse Data


$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()

Delete Microsoft Dataverse Data


$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()

Ready to get started?

Download a free trial of the Microsoft Dataverse Data Provider to get started:

 Download Now

Learn more:

Microsoft Dataverse Icon Microsoft Dataverse ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Microsoft Dataverse data including Accounts, Entities, and more!