Teams Channel

Glenn Maxwell 10,781 Reputation points
2022-07-18T20:52:39.357+00:00

Hi All

I am new to teams, i have a Team i.e office 365 unified group lets say unifiedgroup1@Company portal .com and the owner of this unified group is user1@contos.com i have two requirements.

  1. export all channels(private and public) from PowerShell of this team unifiedgroup1@Company portal .com.
  2. Create a private teams channel priv1 from PowerShell under the parent team unifiedgroup1@Company portal .com and make user1 as the owner.
  3. create a public teams channel pub1 from PowerShell under the parent team unifiedgroup1@Company portal .com and make user1 as the owner.
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,627 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,386 questions
{count} votes

Accepted answer
  1. Dillon Silzer 56,681 Reputation points
    2022-07-18T21:48:53.27+00:00

    Requirements to run scripts (powershell commands before you start):

    Set-ExecutionPolicy Unrestricted  
      
    Import-Module -name MicrosoftTeams  
      
    Connect-MicrosoftTeams  
    

    1) export all channels(private and public) from PowerShell of this team unifiedgroup1@Company portal .com.

    Find your team name in Teams Admin or the display name that you see in Teams and edit the "YOUR TEAM NAME" part of the script.

    $Result = @()  
    #Get all teams  
    $AllTeams= Get-Team -DisplayName "YOUR TEAM NAME"  
    $TotalTeams = $AllTeams.Count  
    $i = 0  
    #Iterate teams one by one and get channels   
    ForEach ($Team in $AllTeams)  
    {  
    $i++  
    Write-Progress -Activity "Fetching channels from $($Team.Displayname)" -Status "$i out of $TotalTeams completed"  
    Try  
    {  
    #Get channels  
    $TeamChannels = Get-TeamChannel -GroupId $Team.GroupId  
       
    #Iterate channels one by one and add to the result array  
    ForEach ($Channel in $TeamChannels)  
    {  
    #Add channel info to the result array  
    $Result += New-Object PSObject -property $([ordered]@{  
    TeamName = $Team.DisplayName  
    TeamVisibility = $Team.Visibility  
    ChannelName = $Channel.DisplayName  
    GroupId = $Team.GroupId  
    ChannelId = $Team.ChannelId  
    })  
       
    }  
    }  
    Catch   
    {  
    Write-Host "Error occurred for $($Team.Displayname)" -f Yellow  
    Write-Host $_ -f Red  
    }  
    }  
       
    #Export the result to CSV file  
    $Result | Export-CSV "C:\AllTeamChannels.CSV" -NoTypeInformation -Encoding UTF8  
    

    Script from https://morgantechspace.com/2021/12/export-channels-and-members-from-all-teams-using-powershell.html

    2) Create a private teams channel priv1 from PowerShell under the parent team unifiedgroup1@Company portal .com and make user1 as the owner.

    New-TeamChannel -GroupId ObjectId -DisplayName "priv1" -MembershipType Private -Owner UserObjectID  
    

    Find the ObjectId in Azure AD > Groups > Choose the group > Under Overview > Object ID

    222021-image.png

    Find the UserObjectID in Azure AD > User > Choose user1 > Under Profile > Object ID

    221946-image.png

    https://learn.microsoft.com/en-us/powershell/module/teams/new-teamchannel?view=teams-ps

    3) create a public teams channel pub1 from PowerShell under the parent team unifiedgroup1@Company portal .com and make user1 as the owner.

    New-TeamChannel -GroupId ObjectId -DisplayName "pub1" -owner UserObjectId  
    

    (see 2) for ObjectId and UserObjectId)

    -----------------------

    If this is helpful please don't forget to mark as correct answer.


0 additional answers

Sort by: Most helpful