Automate Dynamics NAV Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Dynamics NAV ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Dynamics NAV data including Items, Sales Orders, Purchase Orders, and more!

Are you looking for a quick and easy way to access Dynamics NAV data from PowerShell? We show how to use the Cmdlets for Dynamics NAV and the CData ADO.NET Provider for Dynamics NAV to connect to Dynamics NAV data and synchronize, automate, download, and more.

The CData Cmdlets for Dynamics NAV 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 NAV.

Cmdlets or ADO.NET?

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

After obtaining the needed connection properties, accessing Dynamics NAV data in PowerShell consists of three basic steps.

Before you can connect, OData Services will need to be enabled on the server. Once OData Services are enabled, you will be able to query any Services that are published on the server.

The User and Password properties, under the Authentication section, must be set to valid Dynamics NAV user credentials. In addition, you will need to specify a URL to a valid Dynamics NAV server organization root and a ServerInstance. If there is not a Service Default Company for the server, you will need to set the Company as well.


  1. Install the module:

    Install-Module DynamicsNAVCmdlets
  2. Connect:

    $dynamicsnav = Connect-DynamicsNAV -http://myserver:7048 "$http://myserver:7048" -User "$User" -Password "$Password" -ServerInstance "$ServerInstance"
  3. Search for and retrieve data:

    $name = "Bob" $customer = Select-DynamicsNAV -Connection $dynamicsnav -Table "Customer" -Where "Name = `'$Name`'" $customer

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

    $customer = Invoke-DynamicsNAV -Connection $dynamicsnav -Query 'SELECT * FROM Customer WHERE Name = @Name' -Params @{'@Name'='Bob'}


  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.DynamicsNAV.DynamicsNAVConnection("http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;") $conn.Open()
  3. Instantiate the DynamicsNAVDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Name, Prices_Including_VAT from Customer" $da= New-Object System.Data.CData.DynamicsNAV.DynamicsNAVDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $ $_.prices_including_vat }

Update Dynamics NAV Data


Update-DynamicsNAV -Connection $DynamicsNAV -Columns @('Name','Prices_Including_VAT') -Values @('MyName', 'MyPrices_Including_VAT') -Table Customer -Id "MyId"


$cmd = New-Object System.Data.CData.DynamicsNAV.DynamicsNAVCommand("UPDATE Customer SET Name='Bob' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.DynamicsNAV.DynamicsNAVParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Dynamics NAV Data


Add-DynamicsNAV -Connection $DynamicsNAV -Table Customer -Columns @("Name", "Prices_Including_VAT") -Values @("MyName", "MyPrices_Including_VAT")


$cmd = New-Object System.Data.CData.DynamicsNAV.DynamicsNAVCommand("INSERT INTO Customer (Name) VALUES (@myName)", $conn) $cmd.Parameters.Add(new System.Data.CData.DynamicsNAV.DynamicsNAVParameter("@myName","Bob")) $cmd.ExecuteNonQuery()

Delete Dynamics NAV Data


Remove-DynamicsNAV -Connection $DynamicsNAV -Table "Customer" -Id "MyId"


$cmd = New-Object System.Data.CData.DynamicsNAV.DynamicsNAVCommand("DELETE FROM Customer WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.DynamicsNAV.DynamicsNAVParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()