Microsoft Teams Report extracting owner email address

%3CLINGO-SUB%20id%3D%22lingo-sub-1316283%22%20slang%3D%22en-US%22%3EMicrosoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1316283%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20is%20sad%20and%20strange%20that%20most%20of%20the%20Exchange%20online%20commandlets%20do%20not%20show%20users%20email%20addresses%3C%2FP%3E%3CP%3Efor%20e.g.%20Get-UnifiedGroups%20or%20Get-Recipient%20etc....%3C%2FP%3E%3CP%3EAlso%20at%20the%20time%20as%20the%20number%20of%20teams%20increase%20on%20the%20tenant%20it%20is%20impossible%20to%20generate%20reports%20showing%20Team%20details%20and%20its%20owner%20details%20in%20email%20format%20%3F%3F%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EBR%2C%3C%2FP%3E%3CP%3E%2FHS%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1316283%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1317147%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1317147%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F45912%22%20target%3D%22_blank%22%3E%40Himanshu%20Singh%3C%2FA%3E%26nbsp%3B%2C%20what%20you%20mean%20by%20not%20displaying%20the%20emails%3F%20have%20you%20tried%20selecting%20the%20desired%20object%20attribute%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eget-recipient%20%7C%20select%20PrimarySMTPAddress%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20Unified%20groups%2C%20you%20get%20the%20unified%20group%20primary%20SMTP%20address%20the%20same%20way%3C%2FP%3E%3CP%3EGet-UnifiedGroup%20%7C%20select%26nbsp%3BPrimarySMTPAddress%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20for%20the%20members%2C%20you%20can%20pipe%20it%20like%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-UnifiedGroup%20%7C%20Get-UnifiedGroupLinks%20-LinkType%20Member%20%7C%20select%20PrimarySMTPAddress%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20your%20last%20question%2C%20you%20can%20use%20this%20code%20to%20generate%20the%20report%20displaying%20the%20owner's%20email%20address%20using%20the%20above%20examples.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%24Groups%20%3D%20Get-UnifiedGroup%20%7C%20select%20managedby%2C%20DisplayName%20%23Here%20you%20can%20select%20and%20filter%20the%20groups%20that%20you%20need%20a%20report%20%0A%24Result%20%3D%20%40()%0A%0AForeach(%24Group%20in%20%24Groups)%0A%20%7B%0A%20%20%24MailsOwners%20%3D%20%40()%0A%20%0A%20%20Foreach(%24Owner%20in%20%24Group.ManagedBy)%0A%20%20%20%7B%0A%20%20%20%20%24MailOwner%20%20%20%3D%20%24null%0A%20%20%20%20%24MailOwner%20%20%20%3D%20Get-Recipient%20%24Owner%20%7C%20select%20PrimarySMTPAddress%0A%20%20%20%20%24MailsOwners%20%2B%3D%20%24MailOwner.PrimarySMTPAddress%0A%20%20%20%7D%0A%20%20%0A%20%20%24MailsOwners%20%3D%20%24MailsOwners%20-join%20%22%3B%22%0A%20%20%24Props%20%3D%20%24null%0A%20%20%24Props%20%3D%20%5Bordered%5D%40%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GroupDisplayName%20%3D%20%24Group.DisplayName%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20GroupOwnersMails%20%3D%20%24MailsOwners%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%24Outputtmp%20%20%3D%20%20New-Object%20PSObject%20-Property%20%24Props%0A%20%20%24Result%20%20%20%20%2B%3D%20%20%24Outputtmp%0A%20%7D%0A%0A%20%24Result%20%7C%20Export-Csv%20%22Report.csv%22%20-NoTypeInformation%20-Encoding%20UTF8%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20let%20me%20know%20if%20you%20have%20any%20further%20questions%20about%20this.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EErick%20A.%20Moreno%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1318543%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1318543%22%20slang%3D%22en-US%22%3E%3CP%3EMany%20thanks%20i%20am%20testing%20your%20script%2C%20however%20my%20real%20issue%20is%20the%20time%20this%20reports%20takes%20to%20finish%20i%20have%20more%2010K%20teams%20or%20say%20even%20more%20O365%20groups%20it%20takes%20more%26nbsp%3B%202-3%20hrs%20for%20this%20report%20if%20it%20completes%2C%20as%20for%20last%20few%20times%20powershell%20session%20disconnects%20before%20the%20script%20can%20generate%20all%20details%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ehowever%20to%20save%20sometime%20i%20have%20attempted%20to%20take%20only%20one%20owner%20for%20each%20group%20see%20following%20and%20suggest%20further%20optimization%20if%20possible%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImport-Module%20%24((Get-ChildItem%20-Path%20%24(%24env%3ALOCALAPPDATA%2B%22%5CApps%5C2.0%5C%22)%20-Filter%20Microsoft.Exchange.Management.ExoPowershellModule.dll%20-Recurse%20).FullName%7C%3F%7B%24_%20-notmatch%20%22_none_%22%7D%7Cselect%20-First%201)%3CBR%20%2F%3E%24Session%3DNew-ExoPSSession%3CBR%20%2F%3EImport-PSSession%20%24Session%20-AllowClobber%20-Verbose%3CBR%20%2F%3E%24teamsgroups%20%3D%20(Get-UnifiedGroup%20-ResultSize%20Unlimited%20%7C%20Select%20DisplayName%2CAlias%2CName%2CResourceProvisioningOptions%2CAccessType%2CClassification%2CLanguage%2CExchangeGuid%2CManagedBy)%3CBR%20%2F%3E%23notification%20for%20powershell%3CBR%20%2F%3EWrite-Host%20%22Getting%20Office%20365%20Groups%20created%20with%20MS%20Teams...%20%22%20-ForegroundColor%20Green%3CBR%20%2F%3E%23generate%20array%20for%20teamsgroups%3CBR%20%2F%3E%24teams%20%3D%20%40()%3CBR%20%2F%3E%23loop%20to%20get%20information%3CBR%20%2F%3EForEach%20(%24group%20in%20%24teamsgroups)%7B%3CBR%20%2F%3E%23get-members%20of%20group%3CBR%20%2F%3E%24identity%20%3D%20((%24group).ExchangeGuid)%3CBR%20%2F%3E%24owners%20%3D%20(Get-UnifiedGroupLinks%20-Identity%20%22%24identity%22%20-LinkType%20Owners%20%7C%20Select-Object%20PrimarySMTPAddress)%3CBR%20%2F%3E%24owner%20%3D%20((%24owners%5B0%5D).primarySMTPAddress)%20%7C%20Out-String%3CBR%20%2F%3E%23%20Adding%20pscustomobjets%20entries%20to%20array%3CBR%20%2F%3E%24teams%20%2B%3D%20%5Bpscustomobject%5D%40%7B%3CBR%20%2F%3EDisplayName%20%3D%20(%24group).DisplayName%3CBR%20%2F%3EName%20%3D%20(%24group).Name%3CBR%20%2F%3EAlias%20%3D%20(%24group).Alias%3CBR%20%2F%3EAccessType%20%3D%20(%24group).AccessType%3CBR%20%2F%3EClassification%3D(%24group).classification%3CBR%20%2F%3ECreationApp%3D(%24group).resourceprovisioningoptions%3CBR%20%2F%3ELanguage%20%3D%20(%24group).Language%3CBR%20%2F%3EOwner%20%3D%20(%22%24owner%22)%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%23out%20put%20in%20GridView%20(external%20window)%3CBR%20%2F%3EWrite-Host%20%22Display%20in%20Grid%20View%20Window%20%22%20-ForegroundColor%20Green%3CBR%20%2F%3E%24teams%20%7C%20Out-GridView%20-Title%20%22All%20Office365%20Groups%20created%20in%20MS%20Teams%22%3CBR%20%2F%3E%23out%20put%20in%20powershell%3CBR%20%2F%3E%24teams%20%7C%20Export-Csv%20C%3A%5Ctools%5CTeamsClassi.csv%20-NoTypeInformation%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBR%2C%3C%2FP%3E%3CP%3E%2FHS%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1318822%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1318822%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F45912%22%20target%3D%22_blank%22%3E%40Himanshu%20Singh%3C%2FA%3E%2C%20You%20can%20check%20for%20the%20PSsession%20status%20before%20you%20get%20the%20owners%20every%20iteration.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24PSSessionStatus%20%3D%20%24(Get-PSSession%20-Name%20%24Session.Name%20).State%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf(%24PSSessionStatus%20-eq%20Opened)%3C%2FP%3E%3CP%3E%26nbsp%3B%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%20Run%20the%20code%20to%20obtain%20de%20owners%3C%2FP%3E%3CP%3E%26nbsp%3B%7D%3C%2FP%3E%3CP%3EElse%3C%2FP%3E%3CP%3E%26nbsp%3B%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%23Create%20a%20new%20session%20and%20run%20the%20code%20to%20obtain%20the%20owners%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20an%20alternative%2C%20you%20can%20create%20a%20counter%20that%20increments%20every%20time%20you%20iterate%20inside%20the%20loop%20and%20every%20N%20number%20of%20iterations%20you%20close%20and%20reopen%20the%20PSsession%20(Refreshing%20it).%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20to%20reduce%20loading%20times%20I%20will%20recommend%20only%20import%20the%20cmdlets%20that%20you%20are%20using.%26nbsp%3B%3C%2FP%3E%3CP%3EImport-PSSession%20%24Session%20-AllowClobber%20-Verbose%20-CommandName%20%22Get-UnifiedGroupLinks%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%3C%2FP%3E%3CP%3EErick%20A.%20Moreno%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1319570%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1319570%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89674%22%20target%3D%22_blank%22%3E%40Erick%20A.%20Moreno%20R.%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20found%20out%20this%20one%3C%2FP%3E%3CP%3EUse%20the%20Exchange%20Online%20PowerShell%20V2%20module%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fexchange%2Fexchange-online%2Fexchange-online-powershell-v2%2Fexchange-online-powershell-v2%3Fview%3Dexchange-ps%23how-the-exo-v2-module-works%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fexchange%2Fexchange-online%2Fexchange-online-powershell-v2%2Fexchange-online-powershell-v2%3Fview%3Dexchange-ps%23how-the-exo-v2-module-works%3C%2FA%3E%3CBR%20%2F%3EHow%20the%20EXO%20V2%20module%20works%3CBR%20%2F%3EThe%20Exchange%20Online%20PowerShell%20V2%20module%20contains%20a%20small%20set%20of%20new%20cmdlets%20that%20are%20optimized%20for%20bulk%20data%20retrieval%20scenarios%20(think%3A%20thousands%20and%20thousands%20of%20objects).%3C%2FP%3E%3CP%3EI%20will%20also%20try%20the%20suggestions%20you%20have%20mentioned%2C%3C%2FP%3E%3CP%3Ecould%20you%20please%20share%20how%20to%20add%20so%20that%20it%20continues%20to%20show%20progress%20status%20all%20through...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBR%2C%3C%2FP%3E%3CP%3E%2FHS%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1319800%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20Teams%20Report%20extracting%20owner%20email%20address%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1319800%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89674%22%20target%3D%22_blank%22%3E%40Erick%20A.%20Moreno%20R.%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20finished%20using%20the%20Connect-ExchangeOnline%20-%20it%20only%20generates%20~400%20groups%20whereas%20i%20know%20i%20have%20more%20then%2010K%20appears%20it%20is%20not%20showing%20the%20Archived%20ones%20may%20be%2C%3C%2FP%3E%3CP%3EI%20have%20MFA%20enabled%20i%20-%20storing%20creds%20in%20a%20variable%20doesnt%20help%20%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBR%2C%3C%2FP%3E%3CP%3E%2FHS%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

Hello,

 

It is sad and strange that most of the Exchange online commandlets do not show users email addresses

for e.g. Get-UnifiedGroups or Get-Recipient etc....

Also at the time as the number of teams increase on the tenant it is impossible to generate reports showing Team details and its owner details in email format ???

BR,

/HS

5 Replies

Hello @Himanshu Singh , what you mean by not displaying the emails? have you tried selecting the desired object attribute like:

 

get-recipient | select PrimarySMTPAddress

 

For the Unified groups, you get the unified group primary SMTP address the same way

Get-UnifiedGroup | select PrimarySMTPAddress

 

and for the members, you can pipe it like this.

 

Get-UnifiedGroup | Get-UnifiedGroupLinks -LinkType Member | select PrimarySMTPAddress

 

For your last question, you can use this code to generate the report displaying the owner's email address using the above examples. 

 

$Groups = Get-UnifiedGroup | select managedby, DisplayName #Here you can select and filter the groups that you need a report 
$Result = @()

Foreach($Group in $Groups)
 {
  $MailsOwners = @()
 
  Foreach($Owner in $Group.ManagedBy)
   {
    $MailOwner   = $null
    $MailOwner   = Get-Recipient $Owner | select PrimarySMTPAddress
    $MailsOwners += $MailOwner.PrimarySMTPAddress
   }
  
  $MailsOwners = $MailsOwners -join ";"
  $Props = $null
  $Props = [ordered]@{
                      GroupDisplayName = $Group.DisplayName
                      GroupOwnersMails = $MailsOwners   
                     }

  $Outputtmp  =  New-Object PSObject -Property $Props
  $Result    +=  $Outputtmp
 }

 $Result | Export-Csv "Report.csv" -NoTypeInformation -Encoding UTF8

 

Please let me know if you have any further questions about this. 

 

Regards

Erick A. Moreno

Many thanks i am testing your script, however my real issue is the time this reports takes to finish i have more 10K teams or say even more O365 groups it takes more  2-3 hrs for this report if it completes, as for last few times powershell session disconnects before the script can generate all details

 

however to save sometime i have attempted to take only one owner for each group see following and suggest further optimization if possible

 

Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)
$Session=New-ExoPSSession
Import-PSSession $Session -AllowClobber -Verbose
$teamsgroups = (Get-UnifiedGroup -ResultSize Unlimited | Select DisplayName,Alias,Name,ResourceProvisioningOptions,AccessType,Classification,Language,ExchangeGuid,ManagedBy)
#notification for powershell
Write-Host "Getting Office 365 Groups created with MS Teams... " -ForegroundColor Green
#generate array for teamsgroups
$teams = @()
#loop to get information
ForEach ($group in $teamsgroups){
#get-members of group
$identity = (($group).ExchangeGuid)
$owners = (Get-UnifiedGroupLinks -Identity "$identity" -LinkType Owners | Select-Object PrimarySMTPAddress)
$owner = (($owners[0]).primarySMTPAddress) | Out-String
# Adding pscustomobjets entries to array
$teams += [pscustomobject]@{
DisplayName = ($group).DisplayName
Name = ($group).Name
Alias = ($group).Alias
AccessType = ($group).AccessType
Classification=($group).classification
CreationApp=($group).resourceprovisioningoptions
Language = ($group).Language
Owner = ("$owner")
}
}
#out put in GridView (external window)
Write-Host "Display in Grid View Window " -ForegroundColor Green
$teams | Out-GridView -Title "All Office365 Groups created in MS Teams"
#out put in powershell
$teams | Export-Csv C:\tools\TeamsClassi.csv -NoTypeInformation

 

BR,

/HS

 

@Himanshu Singh, You can check for the PSsession status before you get the owners every iteration. 

 

$PSSessionStatus = $(Get-PSSession -Name $Session.Name ).State 

 

If($PSSessionStatus -eq Opened)

 {

  Run the code to obtain de owners

 }

Else

 {

 #Create a new session and run the code to obtain the owners

}

 

As an alternative, you can create a counter that increments every time you iterate inside the loop and every N number of iterations you close and reopen the PSsession (Refreshing it). 

 

Also to reduce loading times I will recommend only import the cmdlets that you are using. 

Import-PSSession $Session -AllowClobber -Verbose -CommandName "Get-UnifiedGroupLinks"

 

Regards

Erick A. Moreno

 

@Erick A. Moreno R. 

I just found out this one

Use the Exchange Online PowerShell V2 module

https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/exchange-online-powershell-v2/e...
How the EXO V2 module works
The Exchange Online PowerShell V2 module contains a small set of new cmdlets that are optimized for bulk data retrieval scenarios (think: thousands and thousands of objects).

I will also try the suggestions you have mentioned,

could you please share how to add so that it continues to show progress status all through...

 

BR,

/HS

 

 

@Erick A. Moreno R. 

Hi,

 

I just finished using the Connect-ExchangeOnline - it only generates ~400 groups whereas i know i have more then 10K appears it is not showing the Archived ones may be,

I have MFA enabled i - storing creds in a variable doesnt help ??

 

BR,

/HS