PowerShell でDynamics GP Data データをCSV に落としてみた

標準PowerShell cmdlets を使ってDynamics GP テーブルにアクセス。

CData Cmdlets Module for Dynamics GP は、直感的なDynamics GP データ連携を提供する標準cmdlet です。 本記事では、DynamicsGP Cmdlets を使ったサンプルを提供します。

Creating a Connection to Your Dynamics GP Data

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.

$conn = Connect-DynamicsGP  -CompanyId "$CompanyId" -user "$user" -password "$password" -URL "$URL"

Selecting Data

Follow the steps below to retrieve data from the SalesInvoice table and pipe the result into to a CSV file:

Select-DynamicsGP -Connection $conn -Table SalesInvoice | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\mySalesInvoiceData.csv -NoTypeInformation

You will notice that we piped the results from Select-DynamicsGP into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.