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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Extract all guests fro...
Power Automate
Unanswered

Extract all guests from teams and put the guest users into a securty group

(0) ShareShare
ReportReport
Posted on by 1,097

Hi

I have about 200 teams where we have internal users (usertype Member) and external users (usertype Guest).

I want to extract all guests from these 200 teams and put the guest-users in a security group.

 

I can do this by making a flow that follow this logic:

1. Get all teams IDn (i have them stored in dataverse)

2. For each team-ID fetch that teams members.

3. For each member in current team, if usertype = guest then keep going

4. For each member in current team that is a Guest, do a filter array and filter the security groups all members on the current guest user from teams.

5. If i get a result in the filter that is larger than 1, then the user is already in the security group. if i get a result of 0, then the guest user from the team needs to be added to the security group.

 

That is the flow for adding members to the group.

After that flow i do a child flow and run these steps.

 

1. Get all teams IDn (i have them stored in dataverse)

2. For each team-ID fetch that teams members.

3. Put the team members into an variable array (append to array)

Loops all 200 teams and build a huge array with all teams members.

4. Then for each member in the security group do a filter array that checks if each user in teh security group exist in the huge array of members (variable array).

5. If result of the filter array is larger than 0 then user do exist in one of the teams and nothing more is done. But if the result of the filter array is 0, then remove the member from the security group since it is not found in one of the teams.

 

--

 

This seems to work. I have not yet tested it on all 200 teams tho...

But i do not like the flow... it feels to complicated and i am afraid i am doing something wrong. That i will reach some limit in how large an array can be by pushing in 200 teams members into one large list.

 

I am looking for tips if i can do this in a smarter and more effective way. Running this flow for all 200 teams will most likely take well over 60 minutes to complete.

 

Categories:
  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @Oskarkuus,

     

    Have you tried the Graph API approach? For example for the retrieving part of guests you might be able to use  the query below:

     

     

    https://graph.microsoft.com/v1.0/groups?$expand=members($filter=userType eq 'Guest')

     

     

  • Oskarkuus Profile Picture
    1,097 on at

    Thank you. After running my flow the process of identifying the guests are not the most time consuming part of the flow. 

     

    The filter you gave med does not work. It needs to work on this api call

    https://graph.microsoft.com/v1.0/groups/<ID>/members?$select=id,userType,mail,displayName,userPrincipalName

  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @Oskarkuus,

     

    In that query I believe you also need to add the $count and the ConsistencyLevel: eventual header in order to be able to use the $filter:

    https://docs.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0&tabs=http#request-headers

     

    Try something like below:

    https://graph.microsoft.com/v1.0/groups/<ID>/members?$count=true&$filter=userType eq 'Guest'&$select=id,userType,mail,displayName,userPrincipalName

     

    Btw, are you testing in Power Automate flow or in Graph Explorer? I would start with Graph Explorer. That makes testing a bit easier.

  • Oskarkuus Profile Picture
    1,097 on at

    Does not seem that query is supported

    Oskarkuus_0-1662730910798.png

     

    i dont think you can filter on string or something.

  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @Oskarkuus,

     

    In which type of action are you using this query? Some of them don't support certain resource types.

     

    I would suggest using the Send an HTTP request of the Office 365 Groups connector. 

     

    Try a setup like below.

    Don't forget to escape the ? with a /. It does not like it compared to the query in Graph Explorer.

     

    1. The flow setup

    https://graph.microsoft.com/v1.0/groups/@{variables('GroupID')}/members/?$count=true&$filter=userType+eq+'Guest'&$select=id,userType,mail,displayName,userPrincipalName

     

    getguests_ofgroup.png

    2. The test in my dev environment

     

    getguests_ofgroup02.png

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 289

#2
11manish Profile Picture

11manish 288 Super User 2026 Season 2

#3
Henil Profile Picture

Henil 125

Last 30 days Overall leaderboard