Microsoft Graph: Get group info

As mentioned in my previous post here, daily tasks shifted and so I had a closer look into Microsoft Graph. In this post it’s about retrieving group information.


In my daily work, I often have to deal with topics, where I need to collect more information about a group. Yes, the new UI in the AAD portal helps, but doesn’t provide all the information. On the other side there are a ton of PowerShell modules e.g.: MSOL, AzureAD or AzureADPreview.

Sorry, but I’m unhappy as not one module, gives me all information. In fact in some cases I have to use MSOL and AzureADPreview in order to get the whole picture. Besides the fact that some Cmdlets just throw an error in larger environements.


The only solution for me was to use Microsoft Graph and therefore, I wrote a function called Get-MSGraphGroup. Same like my other function Get-MSGraphUser, it incorporates all techniques from Microsoft Graph:

The function has the following parameters:

    This function uses Microsoft Office application for retrieving access token and queries Microsoft Graph for group properties.
    The Microsoft Office with ClientID d3590ed6-52b3-4102-aeff-aad2292ab01c can be used to retrieve an access token with the scopes AuditLog.Read.All, Calendar.ReadWrite, Calendars.Read.Shared, Calendars.ReadWrite, Contacts.ReadWrite, DeviceManagementConfiguration.Read.All, DeviceManagementConfiguration.ReadWrite.All, Directory.AccessAsUser.All, Directory.Read.All, email, Files.Read, Files.Read.All, Group.Read.All, Group.ReadWrite.All, Mail.ReadWrite, openid, People.Read, People.Read.All, profile, User.Read.All, User.ReadWrite, Users.Read
    The parameter Group defines the id of the group. Unless you use the parameter ByMail. If this parameter is used in addition, the function tries to get the id of the group by searching for a group with the specified e-mail address.
.PARAMETER AccessToken
    This optional parameter AccessToken can be used if you want to use your own application with delegated or application permission. The parameter takes a previously acquired access token.
    The parameter ByMail is a switch, which can be used in combination with Group, when an e-mail address instead of an id is used.
    The parameter Filter can be used, when you want to use a complex filter.
.PARAMETER ShowProgress
    The parameter ShowProgress will show the progress of the script.
.PARAMETER ReturnMembers
    Switch to return members of group.
.PARAMETER ReturnMembersTransitive
    Switch to return transitive members of group.
    The parameter Threads defines how many Threads will be created. Only used in combination with MultiThread.
.PARAMETER MultiThread
    The parameters MultiThread defines whether the script is running using multithreading.
.PARAMETER Authority
    The authority from where you get the token.
    Application ID of the registered app.
.PARAMETER ClientSecret
    The secret, which is used for Client Credentials flow.
.PARAMETER Certificate
    The certificate, which is used for Client Credentials flow.
    How many retries for each user in case of error.
    TimeoutSec for Cmdlet Invoke-RestMethod.
.PARAMETER MaxFilterResult
    MaxFilterResult when Filter is used.
    Get-MSGraphGroup -Group -ByMail
    Get-MSGraphGroup -Group 6288514a-9840-4426-as05-d2955a03ea27
    Get-MSGraphGroup -Filter Get-MSGraphGroup -Filter "startswith(mail,'ServicesSale')"
    If you want to use your own application make sure you have all the necessary minimum permission assigned: Group.Read.All (this might change in the future. Consult the full permission reference for Microsoft Graph)

It has basically same functionality like Get-MSGraphUser, with the difference that it retrieves data from groups.


The function also supports multi threading using PowerShell runspaces. On top of this it is important to understand the following parameters:

  • ReturnMembers
  • ReturnMembersTransitive

By default only the total number of members will be returned. IF you need to get all members, you can use one of those switches. Be aware that this can take a while and depends on how many members a group has.

You might wonder about the difference between both:

ReturnMembers will return only members of a group. This can also be another group. It will not recursively resolve all levels down to a user object.

ReturnMembersTransitive will exactly do this for you: recursively retrieve flat list of all users.


Just to give you a real-life example. We receive very often tickets, where it is asked about checking Exchange for issues as it seems not all members of a group received an important e-mail.

Well, before it was some kind of hassle to get the flat list of users. Now with this it’s easy as you can just use Microsoft Graph and transitiveMembers.

Where can I get the code?

As mentioned in previous posts, I’m super lazy and that’s why I have it somehow automated to load all my little helpers in combination with a tweaked PowerShell profile. You can find my little helpers here:

You might wonder about the needed application and permissions. No worries as you can use (partially) the app “Microsoft Office” (appId: d3590ed6-52b3-4102-aeff-aad2292ab01c), which is available to everyone and has even the scope Group.Read.All or Directory.Read.All. Usually these permissions require Global Admin consent!


I hope this code helps YOU in your daily work. Feedback is always welcome!

Microsoft Graph: Get user info

Over the last weeks I had a steep learning curve with Microsoft Graph. In my daily job and especially as we moved to M365 it’s absolutely necessary querying attributes for users.

On-premises you most likely would use Get-AdUser or even just ADSI to do so. With the move to M365 you will call Microsoft Graph. And of course make use of OAuth2.0 flows for authentication and authorization.

Continue reading