Find Private Channels in Ms Teams - Powershell

0

I was wondering if someone can help me with the following script. I want the script to tell me the following:

  1. Tell me all the MS Teams that a user is a member of (this is currently working).
  2. I want to see all the Private MS Team channels of each group.

Example: MS Team Sport

  • Channel “Soccer” - Private Channel
  • Channel “Tennis” - Private Channel
  • Channel “Football” - Public Channel

and so on…

It would be nice if we can put this in an excel document. I wrote a similar script to find Displayname, SMTAddress, and Sharepoint site previously which works, but this would be an add-on.

Thank you, everyone!


Connect-ExchangeOnline
Connect-MicrosoftTeams

    $TeamIDs = Get-Team -User cuba@xyz.com
    foreach ($TeamID in $TeamIDs) {
        Get-UnifiedGroup -Identity $TeamID.GroupID | select GroupId, DisplayName, PrimarySmtpAddress, SharePointSiteUrl
        Get-Team -DisplayName $TeamID.DisplayName | Get-TeamChannel -MembershipType private
    }

Miguel,
Welcome to the forum. :wave:t4:

Without having experiences with or access to Exchange Online and Teams I could imagine that something similar to the following code snippet could meet your requirements. At least it may inspire you of how to move forward. :wink:

It is a common way to collect properties from different sources inside a loop and combining them in one [PSCustomObject].

If you want to have the ouput in an Excel sheet you should urgently take a look at the great module from Doug Finke ImportExcel.

Connect-ExchangeOnline
Connect-MicrosoftTeams

$TeamIDs = Get-Team -User cuba@xyz.com
$ResultList = 
foreach ($TeamID in $TeamIDs) {
    $UnifiedGroupList = 
        Get-UnifiedGroup -Identity $TeamID.GroupID
    $TeamChannel = 
        Get-Team -DisplayName $TeamID.DisplayName | 
            Get-TeamChannel -MembershipType private

    foreach ($UnifiedGroup in $UnifiedGroupList) {
        [PSCustomObject]@{
            GroupID            = $UnifiedGroup.GroupID
            DisplayName        = $UnifiedGroup.DisplayName
            PrimarySmtpAddress = $UnifiedGroup.PrimarySmtpAddress
            SharePointSiteUrl  = $UnifiedGroup.SharePointSiteUrl
            TeamChannel        = $TeamChannel
        }
    }
}
$ResultList |
    Format-Table -AutoSize

$ResultList | 
    Export-Excel 

Thank you so much!
It works locating the DisplayName, Email, Site, but it does not find (or it does not show it properly) the Private channels :frowning:

Since I don’t have any experience with teams administration I don’t know if the Get-Team outputs something what Get-TeamChannel takes in by pipeline as -GroupID and how the output of Get-TeamChannel would look like … sorry.

On top of that I don’t know what relation the output of Get-UnifiedGroup and Get-TeamChannel would have.

Hi, maybe something like this will be helpful for you:

    $UPN = 'test@test.pl'

    $TeamIDs = Get-Team -User $UPN

    $Teams_info =@()

    foreach ($TeamID in $TeamIDs) {

        $Teams = Get-UnifiedGroup -Identity $TeamID.GroupID | select GroupId, DisplayName, PrimarySmtpAddress, SharePointSiteUrl
       
        $TeamsChannelList =  get-teamchannel  -GroupId $TeamID.GroupId 
          
            foreach ($TeamsChannel in $TeamsChannelList) {
      
            $TeamChannelUser = Get-TeamChannelUser -DisplayName $TeamsChannel.DisplayName -groupID $TeamID.GroupId | where {$_.user -eq $UPN}

            if ($TeamChannelUser){

                    $Channel_details = [pscustomobject]@{ 
                                       Team               = $Teams.displayname                        
                                       SharepointUrl      = $Teams.SharePointSiteUrl
                                       SmtpAddress        = $Teams.PrimarySmtpAddress
                                       Channel            = $TeamsChannel.DisplayName   
                                       MembershipType     = $TeamsChannel.MembershipType     
                                       User               = $TeamChannelUser.User
                                       UserRole           = $TeamChannelUser.Role
                    }

            $Teams_info += $Channel_details

            }  
      
      } 

}
$Teams_info

Output
image