![]() |
VOOZH | about |
The CData Cmdlets Module for Dynamics 365 Business Central is a standard PowerShell module offering straightforward integration with Dynamics 365 Business Central. Below, you will find examples of using our D365BusinessCentral Cmdlets with native PowerShell cmdlets.
To authenticate to Dynamics 365 Business Central, you must select an AuthScheme and provide the required properties (OAuth by default).
Specify the . If you have multiple companies in your organization, you must also specify the to indicate which company you would like to connect to. does not need to be specified if you have only one company.
To authenticate with an Access Key, set AuthScheme to "AccessKey" and provide the and properties.
To obtain the and values, navigate to the Users page in Dynamics 365 Business Central and then click on Edit. The User Name and Web Service Access Key values are what you will enter as the and connection string properties. Note that the User Name is not your email address. It is a shortened user name.
If you wish to authenticate through other methods, refer to the Help documentation.
$conn = Connect-D365BusinessCentral -OrganizationUrl "$OrganizationUrl" -InitiateOAuth "$InitiateOAuth"
Follow the steps below to retrieve data from the Accounts table and pipe the result into to a CSV file:
Select-D365BusinessCentral -Connection $conn -Table Accounts | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myAccountsData.csv -NoTypeInformation
You will notice that we piped the results from Select-D365BusinessCentral 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.The following line deletes any records that match the criteria:
Select-D365BusinessCentral -Connection $conn -Table Accounts -Where "Name = MyAccount" | Remove-D365BusinessCentral
The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Dynamics 365 Business Central, checking first whether a record already exists and needs to be updated instead of inserted.
Import-Csv -Path C:\MyAccountsUpdates.csv | %{
$record = Select-D365BusinessCentral -Connection $D365BusinessCentral -Table Accounts -Where ("Id = `'"+$_.Id+"`'")
if($record){
Update-D365BusinessCentral -Connection $d365businesscentral -Table Accounts -Columns ("accountid","Name") -Values ($_.accountid, $_.Name) -Where ("Id = `'"+$_.Id+"`'")
}else{
Add-D365BusinessCentral -Connection $d365businesscentral -Table Accounts -Columns ("accountid","Name") -Values ($_.accountid, $_.Name)
}
}
As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!
Download a free trial of the Dynamics 365 Business Central Cmdlets to get started:
Download NowLearn more:
👁 Dynamics 365 Business Central (NAV) IconAn easy-to-use set of PowerShell Cmdlets offering real-time access to Dynamics 365 Business Central data. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.