Forum Discussion

DazzaR's avatar
DazzaR
Iron Contributor
May 25, 2020
Solved

Find out if a specific list of email addresses are Team owners and of what Teams

Grateful for any help in helping me solve a task for my org.

 

The task is to find out if a group of email addresses are Team owners and of what Teams.

 

I could go one by one and work it out but I'd like something repeatable to run as a report based on a stakeholder providing me with a list of email addresses. 

 

I only have Teams admin and SharePoint admin roles.

 

Thanks, Darrel

 

 

 

  • If you want to use the Azure AD cmdlets, Get-AzureADUserOwnedObject should be the fastest way. Best use Exchange PowerShell though:

     

    Get-UnifiedGroup -Filter "ManagedBy -eq '$dn' -and ResourceProvisioningOptions -eq 'Team'"

     

    where $dn is the DistinguishedName of the user you want to check against.

4 Replies

  • DazzaR's avatar
    DazzaR
    Iron Contributor

    I got the result I wanted. It might not be pretty but it works.

    #Start here and change role to "Member" if want member
    Connect-AzureAD
    
    Connect-MicrosoftTeams
    
    $Owner = 'name@yourorg.com'
    
    $Groups = Get-AzureADUser -ObjectId $Owner | Get-AzureADUserMembership | Where-Object {$_.ObjectType -eq 'Group'}
    $Results = $Groups | ForEach-Object {
      $TeamID = $_.ObjectID
      $TeamMembers = Get-TeamUser -GroupId $TeamID
      $IsOwner = $TeamMembers | Where-Object { $_.User -eq $Owner -and $_.Role -eq "Owner"}
      if ($IsOwner) {
        try {
          Get-Team -GroupID $TeamID | Select-Object -Property DisplayName, Description, Visibility, MailNickName, Classification
        }
        catch
        {}
      }
    }
    
    if (-not($Results))
    {
      Write-Host "$Owner isn’t an owner/member of any Microsoft Team (depending on role you select)"
    } Else {
      Write-Host $Owner
      $Results
    }

    DazzaR 

    • If you want to use the Azure AD cmdlets, Get-AzureADUserOwnedObject should be the fastest way. Best use Exchange PowerShell though:

       

      Get-UnifiedGroup -Filter "ManagedBy -eq '$dn' -and ResourceProvisioningOptions -eq 'Team'"

       

      where $dn is the DistinguishedName of the user you want to check against.

      • DazzaR's avatar
        DazzaR
        Iron Contributor

        VasilMichev thanks. I've sort of muddled through part of that but couldn't get your quickest method to work. I connected to an online session with the correct role and no joy running it. Would I be correct in saying dn is the username I want to check against i.e firstname.lastname@org.com 

Resources