
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!
Categories
Recent Posts
- PowerShell: How to Add an Alias to Every Users Mailbox and Groups in Microsoft 365
- Slack: Disable Entra ID User using a slash command.
- Slack: Retrieve Entra ID (MS365) User Information with a slash command.
- Jira Cloud: Disabling Entra ID User Accounts via Automation and Microsoft Runbook
- Jira Cloud: Restart an Azure VM using JSM Assets and Automation