Loading...

Create a service principal with Power Platform CLI

Create a service principal with Power Platform CLI
Create a service principal with Power Platform CLI Stephane Pelhatre Thu, 03/28/2024 - 14:46
Body

Create a service principal with Power Platform CLI

Introduction

To perform an integration with Dynamics 365 you typically need to set up a service principal in Azure.
To achieve this goal you must complete several steps:

  • Create an Azure App Registration
  • Create a secret for that App Registration
  • Set up API permissions for Dynamics 365
  • Create an Application User in the Power Platform Admin Center
  • Assign permissions to the Application User

A tutorial to perform those actions : https://dynamics-chronicles.com/article/step-step-connect-d365-clientsecret-use-apis

All these manual steps take time. But you can perform them with a Powershell command (pac admin create-service-principal).

Create your service principal

First you have to install Power Platform CLI on your machine.
Power Platform CLI is a command-line interface used to perform various operations in the Power Platform related to environment lifecycle, authentication, and work with Dataverse environments, solution packages, portals, code components.

You can download the MSI file here : https://aka.ms/PowerAppsCLI
Power Platform CLI reference guide : https://learn.microsoft.com/en-us/power-platform/developer/cli/reference/tool

After installing Power Platform CLI open a Powershell command prompt and type the command pac to check that the installation was successful.

Create a service principal with Power Platform CLI

Then type the following command to update to the latest version.

 pac install latest

Next step is to connect to your Dataverse environment with an authentication profile.
To get a list of all authentication profiles type the following command :

pac auth list

Create a service principal with Power Platform CLI

As you can see I have no authentication profile installed.
To create a profile type the following command:

pac auth create -env 

is the environment id of your organisation, which you will find in the Power Platform Admin Center.

Create a service principal with Power Platform CLI

You will be asked to provide your credentials. Below the result :

Create a service principal with Power Platform CLI

The last step is to use the command below :

pac admin create-service-principal  --environment 

Create a service principal with Power Platform CLI

Now you can check the result in your Azure Portal.
As you can see below a new App Registration has been created.


07

A secret with one year validity has been created for the App Registration.


08

And correct permissions have also be added.


09

You can see your new application user in the Power Platform Admin Center.


10
The application user has the security role 'System administrator'.
It is the default security role when you use the command pac admin create-service-principal.
If you want to associate another security role you have to use the option --role.

pac admin create-service-principal  --environment  --role 

Where is the name or ID of security role to be applied to the application user.
Below the command to create a service principal with security role 'Sales Manager' assigned to the application user.


Create a service principal with Power Platform CLI

Create a service principal with Power Platform CLI

Published on:

Learn more
Need help with this product?

We can help you with Create a service principal with Power Platform CLI

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

Featured Articles | Dynamics Chronicles
Featured Articles | Dynamics Chronicles

Welcome to our blog, the content is entirely dedicated to Microsoft Dynamics 365, CRM, Power Platform, Common Data Service (CDS) but also Azure. Follow us !

Share post:

Related posts

Unmanaged developer environments are ending: what to do before December 15

Unmanaged developer environments can no longer be created, are suspended on December 15, 2026 and deleted in January. Who is affected and how ...

1 day ago

Backfill Dataverse prompt columns on existing records

Prompt columns only ran on new or updated rows. A bulk option now fills existing records as a system job: the two settings, the steps and the ...

1 day ago

Reveal a masked Dataverse column with Dataverse.Unmask

A new Power Fx function lets authorised users of a canvas app reveal one masked Dataverse value on demand, while column security stays in char...

1 day ago

Generative pages in model-driven apps: a practical guide

What generative pages are, where they stand in November 2026, the two ways to build them, the code they produce, and the limits to plan for.

4 days ago

Big Update — CRMJetty Dynamics 365 Portal Now Comes with Powerful New Integrations

Enterprise portals are evolving rapidly. They are no longer mere portals through which CRM records can be viewed. Portals are now expected to ...

7 months ago

Power Apps Code Apps in Practice: Recreating Model-Driven App Patterns

Power Apps Code Apps went from preview to general availability in record time. With that, Microsoft has sent a clear signal that it is taking ...

8 months ago

Use XRM type definition in your Javascript file

We implement Javascript webresource for form scripting (form onload, field on change,...). Our code need to follow the official document Xrm o...

9 months ago

Dataverse Functions Deep Dive

Microsoft released in 2024 Dataverse low-code plugins. The promise was great : writing plugins using low-code tools. No need to have developme...

10 months ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.