web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Active Directory User ...
Power Apps
Unanswered

Active Directory User Operations

(0) ShareShare
ReportReport
Posted on by 64

Hello fellas! 🙂

 

I have an interesting and challenging project.

Managing users' groups is always confusing when you have so many User's and Positions in the company, specially when they need to have different access restrictions.

 

So, is there a way to accomplish the following:

Ruxxell_0-1678480284670.png

 

1. Select an user from our AD and show their Position, Manager, and list the group membership.

2. Select a new position for the employee and:

a- Filter managers for the new position (leaving out manager of other departments, in this case only employees in HR with manager in their title) and select one for the employee

b- List the group membership of the new position, highlighting the differences between current groups and new groups

3. Save these changes for the employee to AD.

 

The example above is just illustrative, only the combo box are linked to M365 users.

 

Thank you all! 🙂

 

Best regards,

Russ

 
 

 

 

Categories:
I have the same question (0)
  • Verified answer
    Ruxxell Profile Picture
    64 on at

    Update

     

    Work I've done so far:

    1- Able to select users from AD and show their position, manager, and list the group membership

     

    Ruxxell_1-1679511625244.png

    Combobox to find users has this code:

    Ruxxell_3-1679511754860.png

    Filter(AddColumns(Office365Users.SearchUser({searchTerm:cmbEmpName.SearchText, top:10}) As Temp, "EmplName", IsError(Office365Users.ManagerV2(Temp.Id))),EmplName=false)

     

    The label text for the position has this code:

    Ruxxell_4-1679511853060.png

    cmbEmpName.Selected.JobTitle

     

    Label for manager of the selected user has this code:

    Ruxxell_5-1679511937892.png

    Office365Users.ManagerV2(cmbEmpName.Selected.Id).displayName

     

    To load the groups membership of the user I create a Collection by clicking the icon Update next to the User(employee) name:

    Ruxxell_6-1679512165402.png

    ClearCollect(AzGroupEmployee, AddColumns(AzureAD.GetMemberGroupsV2(cmbEmpName.Selected.Id,false).value, "colGroup", AzureAD.GetGroup(Value).displayName))

    (Tried putting this code on the OnSelect property of the Update icon, but it doesn't work properly)

     

    After creating the Collection, assign the values on a Gallery:

    Ruxxell_7-1679512378632.png

    Gallery Items: AzGroupEmployee

     

    The X next to each group is able to remove group membership for the selected user:

    AzureAD.RemoveMemberFromGroup(ThisItem.Value,cmbEmpName.Selected.Id);

    After removing the membership I rebuilt the Collection to update the Gallery in real time:

    ClearCollect(AzGroupEmployee,AddColumns(AzureAD.GetMemberGroupsV2(cmbEmpName.Selected.Id, false).value, "colGroup", AzureAD.GetGroup(Value).displayName))

     

    The Collection for the Employee group membership:

    Ruxxell_8-1679513140060.png

    You wanna work with the Column Value to remove/add group membership, value is the Group ID in Active Directory.

     

    2- Assigning new position

    Ruxxell_9-1679513558190.png

    Basically the steps to find a new position and listing the groups are the same. What changes here is:

    • On Active Directory you need to have a templates named after the positions (lets call it User-Templates) you want to have and add the groups membership to the User-Templates
    • Leave every User-Template's manager field clear in AD, this way you can filter on the New Position combobox to show only the User-Templates and not all users in AD. So the code for New Position would look like this: Filter(AddColumns(Office365Users.SearchUser({searchTerm:cmbPositions.SearchText, top:10}) As Temp, "Positions", !IsError(Office365Users.ManagerV2(Temp.Id))),Positions=false)

    To add a group membership to the employee I added the + icon next to the name's group for new position with this code: AzureAD.AddUserToGroup(ThisItem.Value, cmbEmpName.Selected.Id).

     

    This is how it looks so far:

    Ruxxell_10-1679515753595.png

     

    The background of the Employee's group membership (left) will be green when the employee is already member of one of the groups for the new position, and the background will be some sort of pink on the new position's group membership (right) when the employee already has this group assigned. This should avoid trying to re-assign a group. To accomplish this, I added this code to the property Fill of the control rectangle on each gallery:

    For Gallery1 (containing the current groups):

    Ruxxell_12-1679516869703.png

    If(ThisItem.colGroup exactin Gallery2.AllItems.colGroup,RGBA(10, 180, 50, .2), RGBA(0,0,0,0))

    For Gallery2(containing future groups membership):

    Ruxxell_13-1679516903636.png

    If(ThisItem.colGroup exactin Gallery1.AllItems.colGroup,RGBA(160, 10, 120, .4), RGBA(0,0,0,0))

     

    What's next?:

    • Add buttons or icons to assign new position and new manager.
    • Add a button or icon to remove manager (I think this is the stone in the shoes)

     

     
     

     

     

  • Verified answer
    Ruxxell Profile Picture
    64 on at

    Update

     

    For this particular project I didn't need to work on "Remove Manager" action. Why? Working on this today, I found that when we assign a manager to an employee, this replaces the current manager.

     

    So, pretty simple, adding a button with this code assign a manager to the user:

    AzureAD.AssignManager(cmbEmpName.Selected.Id,cmbNewManager.Selected.Id)

     Where: cmbEmployee and cmbNewManager name are combo box controls retrieving users from AAD. You can see the code for this on my previous comment.

     

    And this conclude this project. 😉

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard