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]

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
                            

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.

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.

© M365Corner. All Rights Reserved.