Automate Dynamics 365 Integration Tasks from PowerShell

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

The CData ADO.NET Provider for Dynamics 365 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 Dynamics 365.

About Dynamics 365 Data Integration

CData simplifies access and integration of live Microsoft Dynamics 365 data. Our customers leverage CData connectivity to:

  • Read and write data in the full Dynamics 365 ecosystem: Sales, Customer Service, Finance & Operations, Marketing, and more.
  • Extend the native features of Dynamics CRM with customizable caching and intelligent query aggregation and separation.
  • Authenticate securely with Dynamics 365 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 their Dynamics 365 entities - listing, creating, and removing associations between entities.

CData customers use our Dynamics 365 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 Dynamics 365 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 Dynamics 365; this tutorial shows how to use the Provider to create, retrieve, update, and delete Dynamics 365 data.

Once you have acquired the necessary connection properties, accessing Dynamics 365 data in PowerShell can be enabled in three steps.

Edition and OrganizationUrl are required connection properties. The Dynamics 365 connector supports connecting to the following editions: CustomerService, FieldService, FinOpsOnline, FinOpsOnPremise, HumanResources, Marketing, ProjectOperations and Sales.

For Dynamics 365 Business Central, use the separate Dynamics 365 Business Central driver.

OrganizationUrl is the URL to your Dynamics 365 organization. For instance, https://orgcb42e1d0.crm.dynamics.com

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Dynamics 365\lib\System.Data.CData.Dynamics365.dll")
  2. Connect to Dynamics 365:

    $conn= New-Object System.Data.CData.Dynamics365.Dynamics365Connection("OrganizationUrl=https://myaccount.operations.dynamics.com/;Edition=Sales;InitiateOAuth=GETANDREFRESH;")
    $conn.Open()
  3. Instantiate the Dynamics365DataAdapter, execute an SQL query, and output the results:

    $sql="SELECT GoalHeadingId, Name from GoalHeadings"
    
    $da= New-Object System.Data.CData.Dynamics365.Dynamics365DataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
        Write-Host $_.goalheadingid $_.name
    }

Update Dynamics 365 Data

$cmd =  New-Object System.Data.CData.Dynamics365.Dynamics365Command("UPDATE GoalHeadings SET Name='MyAccount' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Dynamics365.Dynamics365Parameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()

Insert Dynamics 365 Data

$cmd =  New-Object System.Data.CData.Dynamics365.Dynamics365Command("INSERT INTO GoalHeadings (Name) VALUES (@myName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Dynamics365.Dynamics365Parameter("@myName","MyAccount")))
$cmd.ExecuteNonQuery()

Delete Dynamics 365 Data

$cmd =  New-Object System.Data.CData.Dynamics365.Dynamics365Command("DELETE FROM GoalHeadings WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Dynamics365.Dynamics365Parameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()

Ready to get started?

Download a free trial of the Dynamics 365 Data Provider to get started:

 Download Now

Learn more:

Dynamics 365 Icon Dynamics 365 ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Dynamics 365 data including Leads, Contacts, Opportunities, Accounts, and more!