Creating Service Principals Really Easily Using Pac Cli

2 Comments

When creating integrations with Dynamics 365, one of the common steps is to set up a service principal in Azure. There are several steps to set this up, including:

  • Creating an Azure App Registration
  • Creating a secret
  • Setting up API permissions
  • Creating an Application User in the Power Platform Admin Center
  • Assigning permissions to that Application User

What if I told you you can do all of this with one PowerShell command? Let’s take a look at pac admin create-service-principal.

First, get the Environment Id for your org, which you will find in the Power Platform Admin Center here:

Open the pac cli in PowerShell and run the command below to connect to your environment:

pac auth create -env <environment id>

Make sure your org is properly selected (if you have other connections) with pac auth select.

Now run the command below to create the service principal:

pac admin create-service-principal  --environment <environmentid>

You can see above, this has created everything for us. We can see in Azure the new app registration with secret created:

And API Permissions:

And Application user with System Admin privileges (note you can add a parameter to the command to set the role with -r, but default is System Admin):

That’s it! You have now probably saved a whole lot of time and can start building those integrations.

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

2 Responses to Creating Service Principals Really Easily Using Pac Cli

  1. Hi Carl, thanks for posting this and it’s really come in handy. But normally if we want to create the one app registration to be used across DEV-TEST-PROD environments (because we shouldn’t need to set up different credentials for different environments), in that case, is there additional powershell command we can use, instead of keep creating new app registrations for each environment, while still automatically creating the other good stuff?

Leave a Reply

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