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 Automate / Add/Invite Guest User ...
Power Automate
Unanswered

Add/Invite Guest User to Azure Active Directory and then add users to AAD groups

(0) ShareShare
ReportReport
Posted on by 14

I am brand new to Power Automate. I am looking to do the following.

 

Create a flow that's triggered by a Microsft form submission.

1) I have created a Microsoft form with a number of fields; full-name, surname, email address and semi-colon list of "AAD group names" separated by a semi-colon(s).

2)  I have been following the following article.

Create AAD Guest User with Invitation

3) I have created and tested the following which works;

    - One Microsoft form will fields; fullname, surname, email-address and AAD-groups. NB: the AAD group name value format is.

    "aad-grp-name1;aad-grp-name2,aad-grp-name3"

    - The 'flow' checks to see if the 'email address' exists in AAD and if it doesn't the 'flow' creates a AAD 'guest' user and sends out an email  invitation - this all works.

 

4) What I need help with (code and screen-shots if possible) in 'flow'...

   After the AAD 'guest user' creation...

- Split the AAD group string in to individual groups (maybe in to a string array)???

- Loop through the array contanining and for each AAD group..  

   - Check the group exists in AAD. If the group exists add the 'guest' user if they're not in the group already.

   - If the AAD group doesn't exist ignore and move on to the next group in the array OR the user already in the grou.

 

red71_0-1661954570837.png

 

 

Regards

   

 

Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,189 Most Valuable Professional on at

    Hi @red71,

     

    Like you mentioned, you could split the answer to turn it into an array which you can use within an apply to each loop. Within that loop you can use Graph API to $filter the groups on for example the mailnickname property. If it comes up with no results you can skip it. That skip part can be done with a condition.

     

    Below is an example.

     

    Split function. Replace it by your question id:

    split(outputs('Get_response_details')?['body/ra347e34f17ea4e67afab9ee28ff44504'], ';')

     

    Graph API URI to find the group of the current item in the loop:

    https://graph.microsoft.com/v1.0/groups/?$filter=mailnickname eq '@{item()}'

     

    Check if it returns empty or not:

    length(body('Send_an_HTTP_request')['value'])

    is not equal to 0

     

    Group Id of the first result found:

    body('Send_an_HTTP_request')['value'][0]['id']

     

    filteronnickname.png

  • red71 Profile Picture
    14 on at

    Thanks very much. I have followed your guidance and all is good accept last step.

     

    Happy to accept this as the answer.

     

    The issue with the "add member to AAD group" part.

     

    I am not sure where the 'id' is coming from? (however I think I know the issue)

     

    red71_0-1661973798081.png

    For the add/create AAD user I am actually using a 'HTTP Post' which returns json of the form...

     

    {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#invitations/$entity",
    "id": "3e0306e2-fc96-3a44-78de-753723fe4d17",
    "inviteRedeemUrl": "redacted",
    "invitedUserDisplayName": "John Doe",
    "invitedUserType": "Guest",
    "invitedUserEmailAddress": "jdoe@yahoo.com",
    "sendInvitationMessage": true,
    "inviteRedirectUrl": "https://portal.azure.com/",
    "status": "PendingAcceptance",
    "invitedUserMessageInfo": {
    "messageLanguage": null,
    "customizedMessageBody": "",
    "ccRecipients": [
    {
    "emailAddress": {
    "name": null,
    "address": null
    }
    }
    ]
    },
    "invitedUser": {
    "id": "23d55bef-Fgha-4dfb-99f3-f8d03ce9c3d0"
    }
    }

    The invitedUser.idholds the value which is the object-id of the user in AAD however I don't know how to reference this field in the last step in adding the user to the AAD group - can you help? 

     

     

     

     

     

     

  • Verified answer
    Expiscornovus Profile Picture
    33,189 Most Valuable Professional on at

    Hi @red71,

     

    In your setup you could use the following expression to retrieve the id of the user:

    body('HTTP')['invitedUser']['id']

     

    getuser_action_replacement.png

     

    Btw, I was using the user id from a Get user action. Which does not work for your setup, I have changed to the above setup.

     

    getuser_action.png

  • Verified answer
    red71 Profile Picture
    14 on at

    Thanks very much for your help. Everything works well.

  • Jonathan-101 Profile Picture
    230 on at

    Hi @red71 

     

    This is exactly what I am looking for. Is it possible that you could share the full flow please, including the initial few steps?

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard