Add and Remove User to/from Microsoft 365 AD Group through Power Apps

There is a requirement to add and remove User to/from Azure AD group of Type Microsoft 365 using Power Apps.

There are below steps:

  • Gallery (galGroupMembers) to display the list of existing Users in a selected AD Group
  • Create People Picker (cmbUser) to search User
  • Button (btnAddUser) to Add user to AD Group
  • Button (btnRemoveUser) to Remove User

Gallery to display list of users

You will get Group ID from Azure Group properies. Write below code in Items property of galGroupMembers Gallery. You can then use ThisItem.displayName and ThisItem.mail as text properties of Labels to display User Name and User Mail in the gallery.

Office365Groups.ListGroupMembers(groupID).value

People Picker to search a User

Use a ComboBox cmbUser and write below in Items Property. Write [“DisplayName”,”Mail”] in SearchFields and [“DisplayName”,”Mail”] in DisplayFields properties of Combobox

Office365Users.SearchUser({searchTerm:cmbUser.SearchText, top:10})

Add User to AD Group

Add below on OnSelect property of btnAddUser Button

Office365Groups.AddMemberToGroup(groupID, cmbUser.Selected.Mail);

Remove User from AD Group

Add below on OnSelect property of btnRemoveUser Button. Please Note only Group Owners can remove a user from the Group.

Office365Groups.RemoveMemberFromGroup(groupID, galGroupMembers.Selected.mail);
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s