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
Comments
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.