MS Teams – export team owners

Run the following script to export all team owners and the associated team site

#connecting to Teams
Connect-MicrosoftTeams

# Get all the teams from tenant  
$teamColl=Get-Team  
 
# Loop through the teams  
foreach($team in $teamColl)  
{  
    Write-Host -ForegroundColor Magenta "Getting all the owners from Team: " $team.DisplayName  
 
    # Get the team owners  
    $ownerColl= Get-TeamUser -GroupId $team.GroupId -Role Owner  
 
    #Loop through the owners  
    foreach($owner in $ownerColl)  
    {  
    $array=[ordered]@{
              "Owner"=$owner.User;
              "Name"=$owner.Name ; 
 
    } 
    $obj=New-Object -TypeName psobject -Property $array
    Export-Csv -path "c:\temp\TeamsOwners.csv" -InputObject $obj -Append -NoTypeInformation     
}
}