The Get-MgTeamMember cmdlet in Microsoft Graph PowerShell retrieves the members of a specific Microsoft Team, including owners, members, and guests. It provides administrators with visibility into team memberships, which can be expanded to include detailed user information by combining it with the Get-MgUser cmdlet.
Managing Teams memberships at scale can be challenging, especially in large organizations. The Get-MgTeamMember cmdlet allows administrators to:
It’s an essential cmdlet for Microsoft 365 automation and governance.
Before using this cmdlet, connect to Microsoft Graph with the required permissions:
Connect-MgGraph -Scopes "TeamMember.Read.All"
You must also have appropriate access rights to view membership information in the specified Team.
The basic syntax is simple — you specify the Team ID to fetch its members:
Get-MgTeamMember -TeamId <team-id>
By default, this cmdlet returns only the Team member IDs. To get user details (like Display Name or UPN), you need to pass the output to Get-MgUser.
This example retrieves all members (owners and users) of a specific Microsoft Team.
Get-MgTeamMember -TeamId <team-id>
This command lists the user IDs of all members in the specified Team.
Note: By default, the Get-MgTeamMember cmdlet only returns member IDs. To view user details, pass the results to the Get-MgUser cmdlet.
$teamId = "9f47ec97-db44-41db-8867-3793cff0a49a"
# Get all team members
$teamMembers = Get-MgTeamMember -TeamId $teamId -All
# Retrieve detailed information for each team member
$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
}
}
}
# Display the team member details
$teamMemberDetails | Format-Table -AutoSize
This example fetches all members from a specified Team and retrieves detailed user information for each member such as Display Name and UserPrincipalName.
| Key Point | Details |
|---|---|
| Cmdlet Name | Get-MgTeamMember |
| Purpose | Retrieves members of a Microsoft Team |
| Required Scope | TeamMember.Read.All |
| Primary Parameter | TeamId |
| Automation Benefit | Enables administrators to automate membership audits and reporting |
| Use Case | Identifying, exporting, or verifying Microsoft Teams memberships |
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