How To access Microsoft Dataverse table using Dynamics 365 Web API in PowerShell

Introduction

In this article, we will learn on what are the prerequisites for accessing Dataverse table using PowerShell. PowerShell is powerful tool while working on migrations, performing admin tasks, automating tasks.

Prerequisites:
– Global admin rights

Below are the steps:         

  1. Register an Azure AD app
    • Sign in to the Azure portal with admin account, select App registration and click on New registration.
      You can also access Azure portal from Microsoft 365 admin center and navigating to Azure Active Directory.
    • Enter app name, account type, redirect URI and click on register.
    • Copy application client id from application overview page, as we need this for the application authentication.
    • Select Manifest tab from left navigation, in the manifest editor, set the allowPublicClient* property to true and click on Save.This image has an empty alt attribute; its file name is image-4.png
    • Select API Permissions tab and click on Add a permission.This image has an empty alt attribute; its file name is image-5.png
    • Select APIs my organization uses tab, search for “Dataverse” and selectThis image has an empty alt attribute; its file name is image-6.png
    • Select “Delegated permissions”, check the checkbox option and click on add permission.This image has an empty alt attribute; its file name is image-7.png
  2. Generate the client secret for the new app
    • Select “Certificates & secrets” then “Client secrets” and click on New client secretThis image has an empty alt attribute; its file name is image-8.png
    • Enter client secret description and click on Add.This image has an empty alt attribute; its file name is image-9.png
    • Once client secret is created, copy it’s value, id and store it to secure location.This image has an empty alt attribute; its file name is image-10.png
  3. Adding app users and configure roles in Dataverse environment
    • Sign in to Power Platform admin center as system administrator, navigate to environments tab. Select your environment from the list and click on settingsThis image has an empty alt attribute; its file name is image-11.png
    • On settings page select Users + permissions and click on Application usersThis image has an empty alt attribute; its file name is image-12.png
    • Select New app user to open the Create a new app user tab and click on Add an appThis image has an empty alt attribute; its file name is image-13.png
    • Search for app and click on Add. This image has an empty alt attribute; its file name is image-14.png
    • Select business unit and click on edit icon next to security roles.This image has an empty alt attribute; its file name is image-15.png
    • Select required roles and click on save.
    • This image has an empty alt attribute; its file name is image-16.png
    • Review the create app user page and click on Create.This image has an empty alt attribute; its file name is image-17.png
    • Once Application user is created select user, select details and refresh details to sync the application user name with Azure add app name.This image has an empty alt attribute; its file name is image-18.png
  4. Configure privileges to the selected security roles in Dataverse environment.
    • Sign in to PowerApps site as system administrator, select environment.
    • Click on settings and select Advanced settings.
    • In dynamics 365 portal, click on settings and select security.This image has an empty alt attribute; its file name is image-19.png
    • Click on security roles.This image has an empty alt attribute; its file name is image-20.png
    • Select security role which you’ve configured in previous steps, I will user Basic User role This image has an empty alt attribute; its file name is image-21.png
    • You can view all Dataverse tables in tabs as per type, I have selected custom entities tab for my custom table.
    • Now choose privileges for your table, you wanted to grant permissions such as Create, Read, Write, Delete, etc. and click on Save and close.This image has an empty alt attribute; its file name is image-22.png
  5. Connect to Dataverse environment from PowerShell script1 and get data from table.
    • ADD SCRIPT HERE

Output

Conclusion    

In this blog, we learned how to configure the Azure AD app and its permissions for accessing Dataverse table content from PowerShell to get data using an OAuth token endpoint API call.

In next article we will see how we can create bulk dummy records in Dataverse table using PowerShell script with OAuth token endpoint.

Share on

Leave a Reply

Your email address will not be published. Required fields are marked *