Forum Discussion
Microsoft Teams Report extracting owner email address
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