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
Microsoft 365 Team members are users added to a specific Microsoft Team, giving them access to:
Team members can have different roles, such as owners or standard members, with varying permissions for managing the Team’s settings and content.
The Get-MgTeamMember cmdlet simplifies the process of retrieving information about members of a Microsoft Team. This cmdlet offers:
Before using the Get-MgTeamMember cmdlet, you must install and configure Microsoft Graph PowerShell:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph
Disconnect-MgGraph
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.
Get-MgTeamMember [-TeamId <String>] [CommonParameters]
To fetch members of a specific Team using its unique ID:
Get-MgTeamMember -TeamId "1cbe8c31-589d-453a-a1e5-045f7f00c967"
If you don’t specify the -TeamId parameter, the cmdlet will prompt you to enter the Team ID interactively:
Get-MgTeamMember
By default, Get-MgTeamMember provides member reference IDs (GUIDs), which represent users or service accounts within the Team:
Id ------------------------------------ MCMjMSMjZWFkYTBjY2MtZTQyOC00OWI2LWE2NzYtY2Y4MjRhM2UzODUwIyM3YWM0MDBiMS031 MCMjMSMjZWFkYTBjY2MtZTQyOC00OWI2LWE2NzYtY2Y4MjRhM2UzODUwIyM3YWM0MDBiMS031 MCMjMSMjZWFkYTBjY2MtZTQyOC00OWI2LWE2NzYtY2Y4MjRhM2UzODUwIyM3YWM0MDBiMS031
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
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.