Get-MgGroupMember

What is Get-MgGroupMember?

The Get-MgGroupMember cmdlet in Microsoft Graph PowerShell retrieves the members of a Microsoft 365 group. It can return details about users, service principals, or devices that belong to a group.


Why Use Get-MgGroupMember?

Managing group memberships is critical for access control and collaboration in Microsoft 365. With Get-MgGroupMember, administrators can:

  • Audit group memberships for compliance and reporting.
  • Verify who has access to security or distribution groups.
  • Automate membership checks for onboarding and offboarding.
  • Export detailed user information for analysis.

Prerequisites

Before using this cmdlet, ensure that the Microsoft Graph module is installed and that you’re connected with the proper permissions:

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.Read.All"

How to Use Get-MgGroupMember?

Syntax (essential parameters):

Get-MgGroupMember -GroupId <GroupId>

You can filter, sort, or limit the results, and even retrieve additional user properties for deeper insights.


Get-MgGroupMember Examples

  • Get Members of a Group
  • Get-MgGroupMember -GroupId "<GroupId>"
  • Search Members
  • Get-MgGroupMember -GroupId "<GroupId>" -Search "displayName:John" -ConsistencyLevel eventual
  • Retrieve the Top N Members of the Group
  • Get-MgGroupMember -GroupId "<GroupId>" -Top 10
  • Sort Members
  • Get-MgGroupMember -GroupId "<GroupId>" -Sort "displayName asc" -ConsistencyLevel eventual -CountVariable groupCount
  • Select Group Member User Properties
  • 
     # Retrieve members of a specified group
     $groupMembers = Get-MgGroupMember -GroupId "1cbe8c31-589d-453a-a1e5-045f7f00c967"
     # Initialize an array to store detailed user information
     $userDetails = @()
     # Loop through each group member and retrieve additional properties
     foreach ($member in $groupMembers) {
         $user = Get-MgUser -UserId $member.Id -Property "id, displayName, userPrincipalName"
         $userDetails += [PSCustomObject]@{
             Id                 = $user.Id
             DisplayName        = $user.DisplayName
             UserPrincipalName  = $user.UserPrincipalName
         }
      }
     # Display the detailed user information
     $userDetails | Select-Object Id, DisplayName, UserPrincipalName
    

Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex