Managing Microsoft Teams effectively involves identifying team owners, an essential aspect of team governance. PowerShell provides a powerful way to automate this process. In this guide, we'll show you how to export Microsoft Teams owners to a CSV file using PowerShell.
Get the Team Owners Using PowerShell
Prerequisites
Before you begin, make sure you have the following in place:
- PowerShell Modules: You'll need to install and import the MicrosoftTeams module and the Microsoft Graph PowerShell SDK (
Microsoft.Graph.Users). - Permissions: Ensure you have the necessary permissions within your Microsoft 365 environment to retrieve team and user information.
Note: The legacy AzureAD PowerShell module was retired by Microsoft (it stopped working in production after August 2025). This guide uses the Microsoft Graph PowerShell SDK, which is the current supported replacement for looking up user details such as UserPrincipalName.
Step 1: Install and Import Required Modules
To get started, install and import the necessary PowerShell modules:
Install-Module -Name "MicrosoftTeams" -Force -AllowClobber
Install-Module -Name "Microsoft.Graph.Users" -Force -AllowClobber
Import-Module -Name "MicrosoftTeams"
Import-Module -Name "Microsoft.Graph.Users"
Step 2: Connect to Your Microsoft 365 Tenant
Establish a connection to your Microsoft 365 tenant using PowerShell:
Connect-MicrosoftTeams
Connect-MgGraph -Scopes "User.Read.All"
Step 3: Retrieve Teams and Owners
Run the following script to loop through all teams, retrieve the owners, and export the results to a CSV file:
# Get a list of all teams
$teams = Get-Team
# Create an array to store the results
$results = @()
# Loop through the teams
foreach ($team in $teams) {
$teamDisplayName = $team.DisplayName
$ownerColl = Get-TeamUser -GroupId $team.GroupId -Role Owner
# Loop through the owners
foreach ($owner in $ownerColl) {
$ownerUserId = $owner.UserId
$ownerName = $owner.Name
# Fetch the UPN for the owner
$ownerUser = Get-MgUser -UserId $owner.UserId
$ownerUPN = $ownerUser.UserPrincipalName
# Create a custom object to store the data
$ownerData = New-Object PSObject -Property @{
"TeamDisplayName" = $teamDisplayName
"UserID" = $ownerUserId
"Name" = $ownerName
"UPN" = $ownerUPN
}
# Add the custom object to the results array
$results += $ownerData
}
}
# Export the results to a CSV file with UTF-8 encoding to handle special characters
$results | Export-Csv -Path "TeamOwners.csv" -NoTypeInformation -Encoding UTF8
Summary
Automating the process of exporting Microsoft Teams owners to a CSV file using PowerShell streamlines team management and ensures a structured approach to governance. With the ability to gather and store this data efficiently, organizations can make the most of their collaboration platform.
Please ensure you have the necessary permissions and follow your organization's policies when using this script.
Related
- Create Multiple Microsoft Teams Channels with PowerShell — bulk channel creation using the same MicrosoftTeams module
- How To Add Bulk Users to MS Teams Private Channels — automate private channel membership at scale
- Add Bulk Users To Shared Mailbox Using PowerShell — another bulk Microsoft 365 governance script
Frequently Asked Questions
What permissions do I need to run Get-Team in PowerShell?
You need to be a Global Administrator or Teams Service Administrator to retrieve a list of all teams. Team owners can only retrieve the teams they own.
Can I export Teams members as well as owners?
Yes. Change the -Role Owner parameter in Get-TeamUser to -Role Member to export members. You can also remove the -Role parameter entirely to export all users regardless of role.
Why am I getting an access denied error with Connect-MicrosoftTeams?
Ensure your account has the required admin role and that multi-factor authentication is completed. If your organization uses Conditional Access policies, you may need to use a compliant device or approved client app.
How do I export owners for a specific team only?
Replace $teams = Get-Team with $teams = Get-Team -DisplayName "Your Team Name" to filter by team name, or use -GroupId to target a specific team by its Group ID.
Is the AzureAD module still required for this script?
No. The AzureAD module was retired by Microsoft and no longer works in production tenants. Use the Microsoft Graph PowerShell SDK (Microsoft.Graph.Users) and Get-MgUser instead, as shown above, to fetch the UserPrincipalName (UPN). If you only need the owner name and user ID, you can skip the Graph module entirely and remove the UPN-related lines from the script.
I get an error that "Teams" is not a recognized module name — what happened?
The correct module name is MicrosoftTeams, not "Teams." There has never been an official Teams administration module simply named "Teams" — always install and import MicrosoftTeams to get Get-Team, Get-TeamUser, and Connect-MicrosoftTeams.