Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs
Hi Pine Littman,
Thank you for posting your question in the Microsoft Q&A forum.
Based on your requirements and my research, I’d like to address your questions and provide some suggestions that may help:
1. Which PowerShell cmdlets or scripts are recommended for retrieving Teams data and exporting it into structured reports (CSV/Excel)?
You can retrieve Microsoft Teams data by combining the following cmdlets from the MicrosoftTeams PowerShell module:
- Get-Team: Retrieves a list of all Teams in the tenant.
- Get-TeamUser: Retrieves members and owners of a Team.
- Get-TeamChannel: Retrieves channels within a Team.
- Get-TeamChannelUser: Retrieves members and owners of a channel.
This Get-TeamChannelUser cmdlet is part of the Public Preview version of the Teams PowerShell module. For more information see Install Teams PowerShell public preview.
Before running these cmdlets, make sure you’ve installed and connected to the module:
Install-Module -Name MicrosoftTeams
Connect-MicrosoftTeams <your authentication method>
Note: Microsoft will enforce Multi-Factor Authentication (MFA) for credential-based authentication. For automation scenarios, it’s recommended to use Application-based authentication. See: Application-based authentication in Teams PowerShell Module - Microsoft Teams | Microsoft Learn
Here’s a basic sample script to get Teams, members, channels, and channel users, and export the data to a CSV file:
# Connect to Teams
Connect-MicrosoftTeams
# Output file path
$Path = "TeamsFullReport.csv"
$Results = @()
# Get all Teams
$teams = Get-Team
foreach ($team in $teams) {
$teamName = $team.DisplayName
$groupId = $team.GroupId
# Get Team members and owners
$teamUsers = Get-TeamUser -GroupId $groupId
foreach ($user in $teamUsers) {
$Results += [PSCustomObject]@{
"Team Name" = $teamName
"Entity Type" = "Team"
"Entity Name" = ""
"User Name" = $user.Name
"User Email" = $user.User
"Role" = $user.Role
}
}
# Get Channels in the Team
$channels = Get-TeamChannel -GroupId $groupId
foreach ($channel in $channels) {
$channelName = $channel.DisplayName
# Get Channel members
$channelUsers = Get-TeamChannelUser -GroupId $groupId -DisplayName $channelName
foreach ($cuser in $channelUsers) {
$Results += [PSCustomObject]@{
"Team Name" = $teamName
"Entity Type" = "Channel"
"Entity Name" = $channelName
"User Name" = $cuser.Name
"User Email" = $cuser.User
"Role" = $cuser.Role
}
}
}
}
# Export to CSV
$Results | Export-Csv -Path $Path -NoTypeInformation -Encoding UTF8
This is a simplified sample for reference only. You should modify it to suit your production needs and handle errors, pagination, and performance considerations.
Please note that my test environment may differ from yours, so the script might encounter errors when executed in your setup. If you run into any issues, feel free to return here with the error message or a screenshot so I can assist further. Also, since the script operates at the tenant level, if you're using application-based authentication, make sure the registered app has sufficient permissions — ideally Teams Administrator role or higher — to access the required data.
3. How to Schedule the Reporting Task Automatically (Daily/Weekly)?
You can schedule the script using one of the following recommend methods:
Option 1: Windows Task Scheduler
Use Task Scheduler to run the .ps1 script on a schedule. Guide: How to Schedule PowerShell Script Using Task Scheduler
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link
Option 2: PowerShell Scheduled Job
Use Register-ScheduledJob to create a scheduled job directly in PowerShell.
More info: Register-ScheduledJob (PSScheduledJob) - PowerShell | Microsoft Learn
4. Why am I unable to upload the question with the "Teams Development" tag?
This may be due to a recent migration of the Q&A platform, which can cause temporary issues with tag selection. Thanks for your understanding!
Hope this helps! Let me know if you need further clarification.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread