Automate Dynamics 365 Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Dynamics 365 ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Dynamics 365.

Are you looking for a quick and easy way to access Dynamics 365 data from PowerShell? We show how to use the Cmdlets for Dynamics 365 and the CData ADO.NET Provider for Dynamics 365 to connect to Dynamics 365 data and synchronize, automate, download, 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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Dynamics 365 API, 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.

After obtaining the needed connection properties, accessing Dynamics 365 data in PowerShell consists of three basic 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 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 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 System.Data.CData.Dynamics365.Dynamics365Parameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()