Reporting Teams Channel Email Addresses

Connecting Those Obscure Teams Channel Email Addresses

Updated 10 July 2023

A colleague posed the question of how to find what team a channel email address belonged to. This is more difficult than you might imagine because when Teams creates an email address for a channel (like, the address doesn’t contain any hint that would allow you to connect the address to its channel. Teams can generate email addresses for any type of channel – regular, private, and shared, and the same kind of obfuscated addresses are used for all types. The Teams admin center doesn’t offer any way of reporting channel email addresses – the only out-of-the-box method to see a channel’s email address is with the Get Email Address option in the Teams client.

 Viewing a Teams channel email address
Figure 1: Viewing a Teams channel email address

No matter, I said, PowerShell will do the trick. In fact, I’d been down this path before when I wrote about how to use audit records to know when channels get or lose email addresses. Part of that article looked at reporting the email addresses that exist for channels using a mixture of PowerShell and Graph API requests (the script is available from GitHub). The Graph requests are required because the Get-TeamChannel cmdlet doesn’t include the email address in the set of properties it returns.

Use the Graph to fetch Teams Channels

The script was one of my earliest efforts at using the Graph with PowerShell and like all code, a fresh eye sometimes creates better results. At least, that’s the eternal hope. I decided to use the Microsoft Graph PowerShell SDK this time around. I used version 1.10 of the Graph SDK for this project. You need the Graph Channel.ReadBasic.All permission to access channel settings. (update: I’ve checked the code against Microsoft Graph PowerShell SDK V2).

Three years ago, the Microsoft Graph PowerShell SDK wasn’t in great shape. Some would argue that it’s still not where it should be. I think the SDK has improved greatly, even if its documentation still sucks dirty canal water. In one respect, the biggest benefit of the SDK is that you don’t need to create a registered app in Azure AD to hold the permissions needed to run Graph requests. Some of its cmdlets take care of pagination too.

For many people, the SDK is easier to use than running Graph requests. Once you’ve gotten the hang of API request formats, you’re able to switch between SDK cmdlets and Graph requests, much like people can switch between left-hand and right-hand drive cars. In any case, here’s the code I wrote:

Connect-MgGraph -Scopes Group.Read.All, Directory.Read.All, Channel.ReadBasic.All
[array]$Teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -All
If (!($Teams)) {Write-Host "Can't find any teams - exiting"; break} 
$Teams = $Teams | Sort-Object DisplayName
$ChannelsList = [System.Collections.Generic.List[Object]]::new()
[int]$i = 0
ForEach ($Team in $Teams) {
   $ProgressBar = "Processing Team " + $Team.DisplayName + " (" + $i + " of " + $Teams.Count + ")"
   Write-Progress -Activity "Checking Teams Information" -Status $ProgressBar -PercentComplete ($i/$Teams.Count*100)
   [array]$Channels = Get-MgTeamChannel -Teamid $Team.Id 
   ForEach ($Channel in $Channels) {
     If ($Channel.Email) {
       $ChannelLine = [PSCustomObject][Ordered]@{  # Write out details of the private channel and its members
          Team           = $Team.DisplayName
          Channel        = $Channel.DisplayName
          Description    = $Channel.Description
          EMail          = $Channel.Email
          Id             = $Channel.Id }
       $ChannelsList.Add($ChannelLine) } 
  } #End Foreach Channel
} # End ForEach Team

Refining for Teams-Generated Email Addresses

So far, so good. The only complication is that the Get-MgTeamChannel cmdlet returns the primary SMTP address for the underlying Microsoft 365 group for a team’s General channel even if Teams generates an email address for the channel. In some respects, this is expected because the General channel is the heart of a team. However, you can’t use the group primary SMTP address to send email to the General channel. because Exchange Online delivers any messages sent to this address to the group mailbox.

To find the set of teams-generated addresses, we therefore need to apply an additional filter. This is straightforward because all teams-generated addresses end in “,” the special domain used for this purpose. The command is:

$TeamsEmailAddresses = $ChannelsList | Where-Object {$_.Email -Like "*"}

Figure 2 shows the set of email addresses in my tenant. Most of them are used for testing, which accounts for some of the obscure channel names.

Reporting Teams channel email addresses
Figure 2: Reporting Teams channel email addresses

PowerShell Invaluable to Administrators

Situations like this underline the truth of the assertion that PowerShell is an invaluable tool for Microsoft 365 tenant administrators. No set of administration tools created by a vendor can be all-encompassing and PowerShell’s ability to fill in the gaps is what makes it so useful. Add in the ability to make Graph calls from PowerShell, and you have a very powerful tool indeed.

Learn more about how the Office 365 applications really work on an ongoing basis by subscribing to the Office 365 for IT Pros eBook. Our monthly updates keep subscribers informed about what’s important across the Office 365 ecosystem.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.