SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-1415916%22%20slang%3D%22en-US%22%3EFind%20out%20if%20a%20specific%20list%20of%20email%20addresses%20are%20Team%20owners%20and%20of%20what%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1415916%22%20slang%3D%22en-US%22%3E%3CP%3EGrateful%20for%20any%20help%20in%20helping%20me%20solve%20a%20task%20for%20my%20org.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20task%20is%20to%20find%20out%20if%20a%20group%20of%20email%20addresses%20are%20Team%20owners%20and%20of%20what%20Teams.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20could%20go%20one%20by%20one%20and%20work%20it%20out%20but%20I'd%20like%20something%20repeatable%20to%20run%20as%20a%20report%20based%20on%20a%20stakeholder%20providing%20me%20with%20a%20list%20of%20email%20addresses.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20only%20have%20Teams%20admin%20and%20SharePoint%20admin%20roles.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%20Darrel%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1415916%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdministrator%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAnalytics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1426128%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20out%20if%20a%20specific%20list%20of%20email%20addresses%20are%20Team%20owners%20and%20of%20what%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1426128%22%20slang%3D%22en-US%22%3E%3CP%3EI%20got%20the%20result%20I%20wanted.%20It%20might%20not%20be%20pretty%20but%20it%20works.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23Start%20here%20and%20change%20role%20to%20%22Member%22%20if%20want%20member%0AConnect-AzureAD%0A%0AConnect-MicrosoftTeams%0A%0A%24Owner%20%3D%20'name%40yourorg.com'%0A%0A%24Groups%20%3D%20Get-AzureADUser%20-ObjectId%20%24Owner%20%7C%20Get-AzureADUserMembership%20%7C%20Where-Object%20%7B%24_.ObjectType%20-eq%20'Group'%7D%0A%24Results%20%3D%20%24Groups%20%7C%20ForEach-Object%20%7B%0A%20%20%24TeamID%20%3D%20%24_.ObjectID%0A%20%20%24TeamMembers%20%3D%20Get-TeamUser%20-GroupId%20%24TeamID%0A%20%20%24IsOwner%20%3D%20%24TeamMembers%20%7C%20Where-Object%20%7B%20%24_.User%20-eq%20%24Owner%20-and%20%24_.Role%20-eq%20%22Owner%22%7D%0A%20%20if%20(%24IsOwner)%20%7B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20Get-Team%20-GroupID%20%24TeamID%20%7C%20Select-Object%20-Property%20DisplayName%2C%20Description%2C%20Visibility%2C%20MailNickName%2C%20Classification%0A%20%20%20%20%7D%0A%20%20%20%20catch%0A%20%20%20%20%7B%7D%0A%20%20%7D%0A%7D%0A%0Aif%20(-not(%24Results))%0A%7B%0A%20%20Write-Host%20%22%24Owner%20isn%E2%80%99t%20an%20owner%2Fmember%20of%20any%20Microsoft%20Team%20(depending%20on%20role%20you%20select)%22%0A%7D%20Else%20%7B%0A%20%20Write-Host%20%24Owner%0A%20%20%24Results%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E-ERR%3AREF-NOT-FOUND-%40Darrel%20Richardson%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1426886%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20out%20if%20a%20specific%20list%20of%20email%20addresses%20are%20Team%20owners%20and%20of%20what%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1426886%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20want%20to%20use%20the%20Azure%20AD%20cmdlets%2C%26nbsp%3B%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3EGet-AzureADUserOwnedObject%3C%2FFONT%3E%20should%20be%20the%20fastest%20way.%20Best%20use%20Exchange%20PowerShell%20though%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3EGet-UnifiedGroup%20-Filter%20%22ManagedBy%20-eq%20'%24dn'%20-and%20ResourceProvisioningOptions%20-eq%20'Team'%22%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3Ewhere%20%24dn%20is%20the%20DistinguishedName%20of%20the%20user%20you%20want%20to%20check%20against.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1430434%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20out%20if%20a%20specific%20list%20of%20email%20addresses%20are%20Team%20owners%20and%20of%20what%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1430434%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3Bthanks.%20I've%20sort%20of%20muddled%20through%20part%20of%20that%20but%20couldn't%20get%20your%20quickest%20method%20to%20work.%20I%20connected%20to%20an%20online%20session%20with%20the%20correct%20role%20and%20no%20joy%20running%20it.%20Would%20I%20be%20correct%20in%20saying%20dn%20is%20the%20username%20I%20want%20to%20check%20against%20i.e%20%3CA%20href%3D%22mailto%3Afirstname.lastname%40org.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Efirstname.lastname%40org.com%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1431253%22%20slang%3D%22en-US%22%3ERe%3A%20Find%20out%20if%20a%20specific%20list%20of%20email%20addresses%20are%20Team%20owners%20and%20of%20what%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1431253%22%20slang%3D%22en-US%22%3E%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%3B%22%3ENo%2C%20it's%20the%26nbsp%3B%3CSPAN%20style%3D%22background-color%3A%20%23ffffff%3B%20box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20display%3A%20inline%3B%20float%3A%20none%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoeui%26amp%3Bquot%3B%2C%26amp%3Bquot%3Blato%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Carial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EDistinguishedName%20%3C%2FSPAN%3Eattribute%3A%3C%2FP%3E%0A%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%20margin%3A%200px%3B%22%3E%24dn%20%3D%20(Get-Mailbox%20user%40domain.com).%3CSPAN%20style%3D%22background-color%3A%20%23ffffff%3B%20box-sizing%3A%20border-box%3B%20color%3A%20%23333333%3B%20display%3A%20inline%3B%20float%3A%20none%3B%20font-family%3A%20%26amp%3Bquot%3B%20segoeui%26amp%3Bquot%3B%2C%26amp%3Bquot%3Blato%26amp%3Bquot%3B%2C%26amp%3Bquot%3Bhelvetica%20neue%26amp%3Bquot%3B%2Chelvetica%2Carial%2Csans-serif%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EDistinguishedName%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

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

 

 

 

4 Replies
Highlighted

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
}

@Darrel Richardson 

Highlighted
Solution

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.

Highlighted

@Vasil Michev 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 

Highlighted

No, it's the DistinguishedName attribute:

 

$dn = (Get-Mailbox user@domain.com).DistinguishedName