As teams is a popular collaboration tool in many companies’ schools, reporting on the team’s membership has become necessary.

Properties of member:

  • UserId: 32 chars
  • User: the UPN format, such as
  • Name: display name, usually in the format of Firstname lastname
  • Role: could be owner, member, guest


below script generate a CSV file for each team.

$userid = ""
$Creds = Get-Credential $userid

Connect-MicrosoftTeams -Credential $Creds

#generate array for custom object
$teamsinfo = @()
#get all teams from organisation
$teams = Get-Team | where-object {$_.DisplayName -like ("2022*")}

ForEach ($team in $teams) 
    $displayname = ($team.DisplayName)
    $Description = ($team.Description)
    $groupid = $team.groupid
    $displayname = ($team.DisplayName)
    $members = Get-TeamUser -GroupId $groupid -Role Member

    $CSVPath = "C:\Temp\"+$displayname +".csv"
    Write-Host "Group Name:" $displayname -ForegroundColor Green

    $OutArray = @() 
    foreach ($member in $members) {
         $member_name = $member.Name.ToString()
         echo $member_name
         $member = $member.User.ToString()

         echo $member
         $OutArray += New-Object PsObject -Property @{ 
         'Display name' = $member_name
         'EmailAddress' = $member 

    $OutArray | Export-Csv $CSVPath -NoTypeInformation


#Remove the session
Remove-PSSession $Session