m365Corner
M365 Blogs

Ultimate Guide for Using Get-MgTeamMember Cmdlet

Microsoft Teams has revolutionized collaboration in the workplace, making it easier for teams to communicate, share files, and manage projects. As a Microsoft 365 administrator, managing Teams memberships is a critical part of ensuring the right people have access to the right resources.

The Get-MgTeamMember cmdlet, part of the Microsoft Graph PowerShell module, provides a programmatic way to retrieve team member details, automate membership audits, and integrate member data into workflows. This guide walks you through the cmdlet’s usage with practical examples and best practices

Who Are Microsoft 365 Team Members?

Microsoft 365 Team members are users added to a specific Microsoft Team, giving them access to:

  • Chat and video conferencing.
  • Shared files and document collaboration via SharePoint.
  • Task management using Planner.
  • Group calendars and shared mailboxes.

Team members can have different roles, such as owners or standard members, with varying permissions for managing the Team’s settings and content.

Why Use Get-MgTeamMember?

The Get-MgTeamMember cmdlet simplifies the process of retrieving information about members of a Microsoft Team. This cmdlet offers:

  • Efficiency: Automate the retrieval of member data for multiple Teams.
  • Scalability: Handle large organizations with hundreds of Teams and thousands of members.
  • Integration: Combine with other cmdlets for advanced reporting and management workflows.

Setting Up Microsoft Graph PowerShell

Before using the Get-MgTeamMember cmdlet, you must install and configure Microsoft Graph PowerShell:

  1. Install the Module:
    Install-Module Microsoft.Graph -Scope CurrentUser
  2. Connect to Microsoft Graph:
     Connect-MgGraph
  3. Disconnect After Use:
    Disconnect-MgGraph

Exploring the Get-MgTeamMember Cmdlet

The Get-MgTeamMember cmdlet is used to retrieve details about the members of a specific Microsoft Team. Let’s explore its usage with detailed examples.

Cmdlet Syntax

Get-MgTeamMember [-TeamId <String>] [CommonParameters]

Key Parameters & Configuration Options (Quick Reference)

Understanding the available parameters helps optimize queries and handle large Teams effectively.

Parameter Purpose
-TeamId Retrieve members of a specific Team
-All Fetch all members (handles pagination)
-Top Limit number of results
-Filter Filter members based on conditions
-Search Search members by keyword
-Property Select specific properties
-ExpandProperty Expand related objects
💡 The cmdlet supports pagination and filtering, making it suitable for large Teams with many members.

Usage Examples

1. Passing Team ID Directly

To fetch members of a specific Team using its unique ID:

Get-MgTeamMember -TeamId "1cbe8c31-589d-453a-a1e5-045f7f00c967"

2. Passing Team ID When Prompted by Console

If you don’t specify the -TeamId parameter, the cmdlet will prompt you to enter the Team ID interactively:

Get-MgTeamMember

3. Get-MgTeamMember Returns Only Member Ref IDs by Default

By default, Get-MgTeamMember provides member reference IDs (GUIDs), which represent users or service accounts within the Team:

Id  
------------------------------------  
MCMjMSMjZWFkYTBjY2MtZTQyOC00OWI2LWE2NzYtY2Y4MjRhM2UzODUwIyM3YWM0MDBiMS031 
MCMjMSMjZWFkYTBjY2MtZTQyOC00OWI2LWE2NzYtY2Y4MjRhM2UzODUwIyM3YWM0MDBiMS031
MCMjMSMjZWFkYTBjY2MtZTQyOC00OWI2LWE2NzYtY2Y4MjRhM2UzODUwIyM3YWM0MDBiMS031 

4. Get Detailed User Information

To fetch detailed information (e.g., display names, UPNs, emails, including the UserID) of Team members, combine Get-MgTeamMember with Get-MgUser:

$teamId = "9f47ec97-db44-41db-8867-3793cff0a49a"
$teamMembers = Get-MgTeamMember -TeamId $teamId -All
$teamMemberDetails = foreach ($member in $teamMembers) {
    $additionalProps = $member.AdditionalProperties
    $userId = $additionalProps["userId"]
    if ($userId -ne $null -and $userId -ne "") {
        $user = Get-MgUser -UserId $userId
        [PSCustomObject]@{
            Id = $user.Id
            DisplayName = $user.DisplayName
            UserPrincipalName = $user.UserPrincipalName
        }
    }
}
$teamMemberDetails | Format-Table -AutoSize
                    

When Should You Use Get-MgTeamMember?

Use the Get-MgTeamMember cmdlet in the following scenarios:

  • Auditing Team memberships for compliance and governance
  • Generating membership reports for administrators
  • Validating access control for sensitive Teams
  • Tracking user participation across Teams
💡 This cmdlet is essential for visibility into who has access to what in your Teams environment.

Get-MgTeamMember vs Related Cmdlets

Cmdlet Purpose When to Use
Get-MgTeamMember Retrieve team members Reporting & auditing
Add-MgTeamMember Add users to Teams Provisioning
Remove-MgTeamMember Remove users Access control
Get-MgTeam Retrieve Team details Metadata & settings
💡 These cmdlets together form the Teams membership management toolkit.

Real-World Automation Scenarios

  1. Membership Audit & Compliance
    • Identify who has access to critical Teams
    • Detect unauthorized users
  2. Exporting Team Members to Reports
    • Retrieve members using -All
    • Export to CSV for reporting
  3. Access Validation During Onboarding/Offboarding
    • Ensure new users are added correctly
    • Verify removed users no longer have access
  4. Cross-Team Membership Analysis
    • Combine with Get-MgTeam to loop through Teams
    • Build tenant-wide membership reports
💡 These scenarios highlight how Get-MgTeamMember is primarily used for governance and reporting workflows.

Common Limitations & Considerations

Strengths

  • Provides detailed membership information/li>
  • Supports filtering and pagination
  • Essential for reporting and audits

Limitations

  • Requires TeamId (no direct “get all members across all Teams” in one call)
  • Does not return all user attributes by default
  • Large Teams require pagination handling
💡 Using -All helps retrieve complete results in large Teams.

Pro Tips for Using Get-MgTeamMember

  • Use -All for large Teams to avoid missing members
  • Combine with Get-MgTeam for tenant-wide reporting
  • Use Select-Object to extract only required fields
  • Export results to CSV for audits
  • Handle pagination carefully to avoid incomplete data
💡 Efficient querying reduces API load and improves performance.

Example: End-to-End Teams Membership Reporting

  1. Retrieve all Teams using Get-MgTeam -All
  2. Loop through each Team
  3. Fetch members using Get-MgTeamMember
  4. Export results to CSV
  5. Analyze using Power BI
💡 This enables complete visibility into Teams membership across the tenant.

Frequently Asked Questions (FAQs)

  1. What is Get-MgTeamMember used for?
    Get-MgTeamMember is used to retrieve members of a Microsoft Team using Graph PowerShell for auditing and reporting.
  2. Can I retrieve all members of a Team?
    Yes, using the -All parameter, you can retrieve all members, including large Teams
  3. What permissions are required?
    You need permissions such as TeamMember.Read.All or Group.Read.All, depending on your scope.
  4. Can I get members of all Teams at once?
    Not directly—you need to loop through Teams using Get-MgTeam and then call Get-MgTeamMember.
  5. Does this cmdlet return user details?
    It returns membership details, but for full user properties, you may need additional cmdlets like Get-MgUser.

Best Practices for Get-MgTeamMember

  • Limit Scope for Efficiency: Use filters or parameters to focus on specific Teams or subsets of data, reducing execution time.
  • Combine with Other Cmdlets: Integrate Get-MgTeamMember with cmdlets like Get-MgUser or Remove-MgTeamMember for advanced workflows.
  • Log Your Actions: Keep logs of your scripts and results for audit purposes, especially when handling sensitive membership data.
  • Secure Your Session: Always disconnect from Microsoft Graph after completing tasks to protect your admin account.

Conclusion

The Get-MgTeamMember cmdlet is an invaluable tool for Microsoft 365 administrators, providing a powerful way to query Team memberships. Whether you’re retrieving basic member IDs, fetching detailed user information, or integrating the cmdlet into larger workflows, Get-MgTeamMember simplifies membership management and enhances productivity.

By mastering this cmdlet and following best practices, you can streamline your administrative tasks and ensure effective Team management across your organization.

🚀 Community Edition Released!

Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.

Get it on GitHub Know More