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.

Automate Dynamics 365 Integration Tasks from PowerShell

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 Cmdlets for Dynamics 365 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 Dynamics 365.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to Dynamics 365, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Dynamics 365 data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Dynamics 365. To access Dynamics 365 data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Dynamics 365.

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,


  1. Install the module:

    Install-Module Dynamics365Cmdlets
  2. Connect:

    $dynamics365 = Connect-Dynamics365 -OrganizationUrl "$OrganizationUrl" -Edition "$Edition"
  3. Search for and retrieve data:

    $name = "MyAccount" $goalheadings = Select-Dynamics365 -Connection $dynamics365 -Table "GoalHeadings" -Where "Name = `'$Name`'" $goalheadings

    You can also use the Invoke-Dynamics365 cmdlet to execute SQL commands:

    $goalheadings = Invoke-Dynamics365 -Connection $dynamics365 -Query 'SELECT * FROM GoalHeadings WHERE Name = @Name' -Params @{'@Name'='MyAccount'}


  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=;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 $ }

Update Dynamics 365 Data


Update-Dynamics365 -Connection $Dynamics365 -Columns @('GoalHeadingId','Name') -Values @('MyGoalHeadingId', 'MyName') -Table GoalHeadings -Id "MyId"


$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


Add-Dynamics365 -Connection $Dynamics365 -Table GoalHeadings -Columns @("GoalHeadingId", "Name") -Values @("MyGoalHeadingId", "MyName")


$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


Remove-Dynamics365 -Connection $Dynamics365 -Table "GoalHeadings" -Id "MyId"


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