Dave Herrell - Blog - IT Toolbox - PowerShell Banner

PowerShell Basics: List all MS Teams, Members & Roles

Microsoft Teams audits can be cumbersome.  Below we have a PowerShell script to help you audit your various Teams and their memberships. This will export a list of all active MS Teams in your MS365 organization, along with each user and the users role within each group. 

To start, make sure you have the Microsoft Teams module installed on PowerShell.

				
					Install-Module MicrosoftTeams
				
			

Next, run the script below.  Make sure you change the output path for the path you wish.  As most full exports, if your organization is large, give it time to export.  

 

				
					# Import the MS Teams module.
Import-Module MicrosoftTeams

# Get all Teams
$teams = Get-Team

# Create an empty object to store all team member information
$allTeamMembers = New-Object System.Collections.ArrayList

# Loop through each Team
foreach ($team in $teams) {
  # Get members and their roles for the current Team
  $members = Get-TeamUser -GroupId $team.GroupId | Select-Object Name, Role 

  # Create a new object for each member
  foreach ($member in $members) {
    $memberInfo = New-Object PSObject -Property @{
      "Team Name" = $team.DisplayName
      "Member Name" = $member.Name
      "Role" = $member.Role
    }
    $allTeamMembers.Add($memberInfo)
  }
}

# Export the results to a CSV file
$exportPath = "C:\Users\dave\Desktop\TeamMembers.csv"
$allTeamMembers | Export-Csv -Path $exportPath -NoTypeInformation

# Informative message
Write-Host "Team member information exported to '$exportPath'"

				
			

Once this is ran, a CSV file export with the list of all your MS Teams, their members and the member roles should be created. 

Hope you find this helpful!