Ready to get started?

Learn more about the CData ADO.NET Provider for Dynamics GP or download a free trial:

Download Now

Automate Dynamics GP Integration Tasks from PowerShell

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

The CData Cmdlets for Dynamics GP are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Dynamics GP.

Cmdlets or ADO.NET?

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

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

To authenticate set the User and Password connection properties.

To connect set the URL to the Web services endpoint; for example, http://{servername}:{port}/Dynamics/GPService. Additionally, set CompanyId; you can obtain this value in the company setup window: Click Tools -> Setup -> Company.

By default, data summaries are not returned to save performance. Set LookupIds to true to return details such as line items; however, note that entities must be retrieved one at a time.

PowerShell

  1. Install the module:

    Install-Module DynamicsGPCmdlets
  2. Connect:

    $dynamicsgp = Connect-DynamicsGP -CompanyId "$CompanyId" -user "$user" -password "$password" -URL "$URL"
  3. Search for and retrieve data:

    $customername = "Bob" $salesinvoice = Select-DynamicsGP -Connection $dynamicsgp -Table "SalesInvoice" -Where "CustomerName = `'$CustomerName`'" $salesinvoice

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

    $salesinvoice = Invoke-DynamicsGP -Connection $dynamicsgp -Query 'SELECT * FROM SalesInvoice WHERE CustomerName = @CustomerName' -Params @{'@CustomerName'='Bob'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.DynamicsGP.DynamicsGPConnection("CompanyId=mycompanyId;user=myuser;password=mypassword;URL= http://{servername}:{port}/Dynamics/GPService;") $conn.Open()
  3. Instantiate the DynamicsGPDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT CustomerName, TotalAmount from SalesInvoice" $da= New-Object System.Data.CData.DynamicsGP.DynamicsGPDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.customername $_.totalamount }