Adding users and groups with security roles assigned to Power Platform environments using CLI

Do you ever find the task of adding users to a Power Platform environment and then having to assign security roles tedious and time consuming? Well, in this post, I’ll show you how to speed this up majorly using the Power Platform CLI (command… READ MORE [https://lewisdoes.dev/blog/adding-users-
female software engineer coding on computer
Photo by ThisIsEngineering on Pexels.com
In: Low Code Lewis Content 🚀

Do you ever find the task of adding users to a Power Platform environment and then having to assign security roles tedious and time consuming? Well, in this post, I’ll show you how to speed this up majorly using the Power Platform CLI (command line interface).

Does the idea of speeding up tedious actions typically executed in the admin center sound good to you? 🤔 Well, lucky for you, this post is the third as part of a quickly growing series on the Power Platform Developer Tools, just starting with the Power Platform CLI, but quickly moving onto all sorts like ALM developer tools, Dataverse developer tools and much more!

Want to make sure you get this content directly in your inbox on a daily basis during my 2023 challenge of #365PostsIn365Days? Subscribe now to ensure you don’t miss any of the upcoming content around these awesome topics! Let me know in the comments of these posts, how you get on with using these tools yourself too! 📧

Subscribe

Adding a user and assigning a security role

So the first thing we’ll look at is adding a user to an environment. Let’s take a look at the command and parameters we can supply, both required and optional.

So the command we’ll need to work with is…

pac admin assign-user

Now this command won’t do anything by itself, and that’s because we need to supply a bit more information if we want to add a user to an environment and assign a security role. If we wanted to do this in the Power Platform Admin Center, we’d need to select the environment, specify the user, and select the security role we want to assign. So, when using a different interface to carry out the same operation, we still need to supply this information! We do this using a number of parameters.

–environment

The first thing we need to specify is the environment ID or URL that we want to add the user to and then assign a security role for.

–role

Now we need to use the role parameter to supply either the name or the ID of the role that we want to assign the user once they’ve been added to the environment.

–user

Finally we need to supply the object ID or the UPN of the user from AAD that we want to add to the environment and assign the security role to.

Example

So now lets take a look at an example of a command with parameters populated that we can use to add a user to an environment and assign a security role to them with.

pac admin assign-user `
  --environment 00000000-0000-0000-0000-000000000000 `
  --user "user@company.com" `
  --role "Basic User"

The command above will add the user ‘user@company.com” to my environment and it will assign the basic user security role.

Adding a group and assigning a security role

Now we aren’t just able to use the CLI to add users to environments with a security role. We can also use it to add groups to an environment and assign a security role.

To work with groups we’ll need to use the following command.

pac admin assign-group

We will use the same following parameters as above…

–environment

–role

But we will also need to supply values for the following parameters.

–group

Here we will supply the AAD object id of a group to assign to the target Dataverse environment

–group-name

Here we will supply the name of the group/team that we want to create in Dataverse.

–membership-type

Here we will supply the team membership type with one of the following values.

  • MembersAndGuests
  • Members
  • Owners
  • Guests

–team-type

Finally we need to supply the type of team to be created.

Using these parameters we’re able to add a group to a dataverse environment now as well and once again, assign a security role.

Upcoming content

So! We’re still just a few posts in to this latest new series on the Power Platform Developer Tools! If you’re enjoying this content so far, make sure you subscribe to get all the latest posts from me directly in your inbox on a daily basis! 📩

Subscribe

Thanks for reading friends! 💖

Written by
Lewis Baybutt
Microsoft Business Applications MVP • Power Platform Consultant • Blogger • Community Contributor • #CommunityRocks • #SharingIsCaring
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to LewisDoesDev.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.