How To Get The Team Owners From All The Teams Using PowerShell

In this blog, you will see how to get the team owners from all the teams using PowerShell.
 
Prerequisites
 
Install the Teams Cmdlets module.
 
 
PowerShell Script
 
Open Notepad and paste the following script. Save the file as Teams.ps1.
  1. # Get the credentials  
  2. $credentials=Get-Credential  
  3.  
  4. # Connect to Microsoft Teams  
  5. Connect-MicrosoftTeams -Credential $credentials  
  6.  
  7. # Get all the teams from tenant  
  8. $teamColl=Get-Team  
  9.  
  10. # Loop through the teams  
  11. foreach($team in $teamColl)  
  12. {  
  13.     Write-Host -ForegroundColor Magenta "Getting all the owners from Team: " $team.DisplayName  
  14.  
  15.     # Get the team owners  
  16.     $ownerColl= Get-TeamUser -GroupId $team.GroupId -Role Owner  
  17.  
  18.     #Loop through the owners  
  19.     foreach($owner in $ownerColl)  
  20.     {  
  21.         Write-Host -ForegroundColor Yellow "User ID: " $owner.UserId "   User: " $owner.User  "   Name: " $owner.Name  
  22.     }      
  23. }  
Open Windows PowerShell window and navigate to the location where the script file was saved.
 
Run the following command.
  1. .\Teams.ps1  
Result
 
 
 
Summary
 
Thus, in this blog, you saw how to get the team owners from all the teams using PowerShell.