none
Powershell script help RRS feed

  • General discussion

  • Hi All,

    I am looking to create a Powershell script and paste it in Azure runbook which will create MS Teams including number of Channels as requested by the user while submitting the request. That means if user wants one channel, then he can put down in the request form (in any portal like SharePoint etc.) and PS script will execute and create a new Team with one channel. If two channels are requested, then new Team with two channels and so on. I have achieved the part of Team name, Team owner, Team Description withing the script, but stuck in the requirement of controlling the Channels. Can you please help me with any idea? It is quite urgent.

    Thanks in advance.

    Sunday, August 25, 2019 9:06 AM

All replies

  • Below Script will Create Microsoft Teams along with multiple Channel Names from the .CSV.

    function Create-Channel
    {   
       param (   
                 $ChannelName,$GroupId
             )   
        Process
        {
            try
                {
                    $teamchannels = $ChannelName -split ";" 
                    if($teamchannels)
                    {
                        for($i =0; $i -le ($teamchannels.count - 1) ; $i++)
                        {
                            New-TeamChannel -GroupId $GroupId -DisplayName $teamchannels[$i]
                        }
                    }
                }
            Catch
                {
                }
        }
    }
    
    function Add-Users
    {   
        param(   
                 $Users,$GroupId,$CurrentUsername,$Role
              )   
        Process
        {
            
            try{
                    $teamusers = $Users -split ";" 
                    if($teamusers)
                    {
                        for($j =0; $j -le ($teamusers.count - 1) ; $j++)
                        {
                            if($teamusers[$j] -ne $CurrentUsername)
                            {
                                Add-TeamUser -GroupId $GroupId -User $teamusers[$j] -Role $Role
                            }
                        }
                    }
                }
            Catch
                {
                }
            }
    }
    
    function Create-NewTeam
    {   
       param (   
                 $ImportPath
             )   
      Process
        {
            Import-Module MicrosoftTeams
            $cred = Get-Credential
            $username = $cred.UserName
            Connect-MicrosoftTeams -Credential $cred
            $teams = Import-Csv -Path $ImportPath
            foreach($team in $teams)
            {
                $getteam= get-team |where-object { $_.displayname -eq $team.TeamsName}
                If($getteam -eq $null)
                {
                    Write-Host "Start creating the team: " $team.TeamsName
                    $group = New-Team -alias $team.TeamsName -displayname $team.TeamsName  -AccessType $team.TeamType
                    Write-Host "Creating channels..."
                    Create-Channel -ChannelName $team.ChannelName -GroupId $group.GroupId
                    Write-Host "Adding team members..."
                    Add-Users -Users $team.Members -GroupId $group.GroupId -CurrentUsername $username  -Role Member 
                    Write-Host "Adding team owners..."
                    Add-Users -Users $team.Owners -GroupId $group.GroupId -CurrentUsername $username  -Role Owner
                    Write-Host "Completed creating the team: " $team.TeamsName
                    $team=$null
                }
             }
        }
    }
    
    Create-NewTeam -ImportPath "C:\Temp\NewTeams.csv"

    CSV File Format:

    Thanks & Regards,


    sharath aluri

    Sunday, August 25, 2019 11:57 AM