Skip to content

Get-MgmtGraphTeamMember

MgmtGraph: Audits Microsoft Team membership

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Teams

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $true, Position = 0)]
    [string]$Identity
)

Process {
    try {
        $members = Get-MgTeamMember -TeamId $Identity -All -ErrorAction Stop
        
        $results = foreach ($m in $members) {
            [PSCustomObject]@{
                DisplayName = $m.DisplayName
                Roles       = $m.Roles -join ", "
                Id          = $m.Id
                UserId      = $m.AdditionalProperties.userId
                Timestamp   = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output ($results | Sort-Object DisplayName)
    }
    catch {
        throw
    }
}

Specifies the ID of the Team to audit.

An interactive directory of PowerShell scripts.