How to export private channels with name and other details like channel ID and other in bulk via powershell script ?

Vinod Survase 4,706 Reputation points
2021-10-19T13:37:57.657+00:00

How to export private channels with name and other details like channel ID and other in bulk via powershell script ?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,161 questions
0 comments No comments
{count} votes

Accepted answer
  1. JimmyYang-MSFT 49,191 Reputation points Microsoft Vendor
    2021-10-20T02:15:53.757+00:00

    Hi @Vinod Survase

    In this blog, it provides the script about how to export only private channel information in Microsoft Teams for your reference:

    Connect-PnPOnline -Scopes ("Group.Read.All", "User.ReadBasic.All")  
    $AccessToken = Get-PnPGraphAccessToken  
      
    $GetAllTeams = Invoke-RestMethod -Headers @{Authorization = "Bearer $AccessToken" } -Uri "https://graph.microsoft.com/beta/groups?`$filter=resourceProvisioningOptions/any(c:c+eq+`'Team`')"  
      
    $ChannelsList = @()  
      
    foreach ($Team in $GetAllTeams.value) {  
      
        $ResponseTeamsChannels = Invoke-RestMethod -Headers @{Authorization = "Bearer $AccessToken" } -Uri ("https://graph.microsoft.com/beta/teams/{0}/channels?`$filter=membershipType eq `'private`'" -f $Team.id)  
        $ResponseTeamsChannels.value.forEach( {  
        if ($_.membershipType -eq "private") {  
            $ChannelObject = "" | Select-Object "TeamName", "TeamId", "ChannelName",  "ChannelId", "Description"  
            $ChannelObject.TeamName = $Team.displayName  
            $ChannelObject.TeamId = $Team.id  
            $ChannelObject.ChannelName = $_.displayName  
            $ChannelObject.ChannelId = $_.id  
            $ChannelObject.Description = $_.description  
            $ChannelsList += $ChannelObject  
        }   
        })      
    }  
      
    $ChannelsList | Export-Csv -Path './PrivateChannels.csv' -NoTypeInformation  
    

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful