Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dridifakhri
New Member

Extract more then 100 members from the Azure Active directory Groups with a power Query function

Hi All,

I want to extract all members from all there group of my company for that i create the first function to extract all group that i need :

-------------------------------------------------------------------------------------------------------------------------------------------

()=>

let
body = "{""grant_type"":""password"", ""resource"":""https://graph.microsoft.com/"", ""client_id"":""*****************************"", ""username"":""*******************"", ""password"":""**************"",""client_secret"": ""******************************"" }",

parsed_json = Json.Document(body),
buildQueryString = Uri.BuildQueryString(parsed_json),
Data = Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/token/", [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(buildQueryString)])),
access_token = Data[access_token]
in
access_token

-------------------------------------------------------------------------------------------------------------------------------------------

Everything is ok for the groups 

After that i use the first function of the Group list to extract the list of corresponding members

 -------------------------------------------------------------------------------------------------------------------------------------------

let
    Source = (GroupID as text)=>
let    
    token= GetMSGraphAccessToken() ,
    Source = Json.Document(Web.Contents("https://graph.microsoft.com",
     [
         RelativePath = "v1.0/groups/" & GroupID & "/members?$count=true",
         Headers=[Authorization="Bearer " &  token]
     ])),
    #"Converted to Table" = Record.ToTable(Source),
    #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Name] <> "@odata.nextLink")),
    Value = #"Filtered Rows"{1}[Value],
    #"Converted to Table1" =  Table.FromList(Value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" =  Table.ExpandRecordColumn(#"Converted to Table1", "Column1", {"@odata.type", "id", "businessPhones", "displayName", "givenName", "jobTitle", "mail", "mobilePhone", "officeLocation", "preferredLanguage", "surname", "userPrincipalName"}, {"Column1.@odata.type", "Column1.id", "Column1.businessPhones", "Column1.displayName", "Column1.givenName", "Column1.jobTitle", "Column1.mail", "Column1.mobilePhone", "Column1.officeLocation", "Column1.preferredLanguage", "Column1.surname", "Column1.userPrincipalName"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Column1",{"Column1.@odata.type", "Column1.businessPhones", "Column1.jobTitle", "Column1.mobilePhone", "Column1.officeLocation", "Column1.preferredLanguage", "Column1.givenName", "Column1.surname", "Column1.userPrincipalName"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column1.displayName", "Analytics Full Name"}, {"Column1.mail", "Analytics Login"}, {"Column1.id", "User id"}})
in
    #"Renamed Columns"
in
    Source

 -------------------------------------------------------------------------------------------------------------------------------------------

knowing that the total number of members of one of the groups are 327, the problem of second function don't give me more then 100 members,

 -------------------------------------------------------------------------------------------------------------------------------------------

I use another function to make a filter with an alphabetical order for the letter A

let
  Source = A("GroupID"),
  Navigation = Source{2}[Value],
  #"Converti en table" = Table.FromList(Navigation, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
  #"Column1 développé" = Table.ExpandRecordColumn(#"Converti en table", "Column1", {"@odata.type", "id", "businessPhones", "displayName", "givenName", "jobTitle", "mail", "mobilePhone", "officeLocation", "preferredLanguage", "surname", "userPrincipalName"}, {"@odata.type", "id", "businessPhones", "displayName", "givenName", "jobTitle", "mail", "mobilePhone", "officeLocation", "preferredLanguage", "surname", "userPrincipalName"}),
  #"Lignes triées" = Table.Sort(#"Column1 développé", {{"displayName", Order.Ascending}}),
  #"businessPhones développé" = Table.ExpandListColumn(#"Lignes triées", "businessPhones"),
  #"Lignes filtrées" = Table.SelectRows(#"businessPhones développé", each Text.StartsWith([userPrincipalName], "a") or Text.StartsWith([userPrincipalName], "A")
   #"Colonnes supprimées" = Table.RemoveColumns(#"Lignes filtrées", {"businessPhones", "@odata.type", "preferredLanguage", "officeLocation", "mobilePhone"}),
  #"Transformer les colonnes" = Table.TransformColumnTypes(#"Colonnes supprimées", {{"id", type text}, {"displayName", type text}, {"givenName", type text}, {"jobTitle", type text}, {"mail", type text}, {"surname", type text}, {"userPrincipalName", type text}})
in
  #"Transformer les colonnes"

 -------------------------------------------------------------------------------------------------------------------------------------------

 but i  dont get the full list of members that their userPrincipalName begins with A

could you help me pLease to extract the complete list

 


 

1 ACCEPTED SOLUTION
rubayatyasmin
Super User
Super User

Hi, @dridifakhri 

 

Try using $top perameter. 

 

Refer: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#top-parameter

 

 

rubayatyasmin_0-1696484097090.png

 

rubayatyasmin_0-1689517080227.png

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

2 REPLIES 2
dridifakhri
New Member

Hi @rubayatyasmin Thank you so much it's Work !!

rubayatyasmin
Super User
Super User

Hi, @dridifakhri 

 

Try using $top perameter. 

 

Refer: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#top-parameter

 

 

rubayatyasmin_0-1696484097090.png

 

rubayatyasmin_0-1689517080227.png

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors