Forum Discussion

Luca VALENTINO's avatar
Luca VALENTINO
Copper Contributor
Mar 21, 2020

Create Teams from csv

I am trying to create Teams from a CSV file

My Csv:

MailTeamsNameTeamsDescriptionTypeTypeTemplateOwners
EV0123EV - ProvaDescrizione1PrivateEDU_Classemail@dom.it
SN0123SN - Prova2Descrizione2PrivateEDU_Classemail@dom.it

This is the code:

 

 

 

 

 

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 -MailNickName $team.Mail -displayname $team.TeamsName -Description $team.TeamsDescription -Visibility $team.TeamType -Template $team.TypeTemplate
                #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:\Users\PC\OFFICE 365\Gruppi_class_team.csv"

 

 

 

 

 

This is the error:

 

 

 

 

 

New-Team : Impossibile convalidare l'argomento sul parametro 'MailNickName'. L'argomento è null o vuoto. Fornire un
argomento che non sia null o vuoto ed eseguire di nuovo il comando.
In riga:19 car:49
+                 $group = New-Team -MailNickName $team.Mail -displayna ...
+                                                 ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-Team], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.TeamsCmdlets.PowerShell.Custom.NewTeam

 

 

 

 

 

 

    • MariusPretorius's avatar
      MariusPretorius
      Steel Contributor

      EDU_ictGeek Luca VALENTINO 

      I am successfully using the script from Create teams in Microsoft Teams through CSV using PowerShell | JiJi Technologies to create multiple teams, including the channels and adding members simultaneously, from a prepared CSV file.

      N.B. I made two small changes to the script.

      • Preparation:
        • I ran PowerShell in Admin mode 
        • I ensured that I had installed the current version of the MicrosoftTeams PowerShell module. I ran the following command in PowerShell (in admin mode) Install-Module -Name MicrosoftTeams -RequiredVersion 1.1.6
      • I made the two highlighted changes to script in the function Create-NewTeam
        • $group = New-Team -MailNickName $team.TeamsName -displayname $team.TeamsName -Template $team.TeamType
        • In the original script it uses -Alias instead of -MailNickName and -AccessType instead of -Template
      • My CSV file had the following headers and example content
        TeamsNameTeamTypeChannelNameOwnersMembers
        21Accounting11EDU_classChannel1; Channel2Teacher1@domain.comMember1@domain.com; member2@domain.com
      • The Team Type is important - you need that in an educational setting to create Class type teams.
      • RicMercene's avatar
        RicMercene
        Copper Contributor

        MariusPretorius Luca VALENTINO EDU_ictGeek 

         

        Good day!

         

        I really need your help... please....

         

        I tried your codes but nothing happened....

         

        attached is my .csv file for reference and below (here) is my code...

         

        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 -DisplayName $team.TeamsName -

        displayname $team.TeamsName -Template $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:\Users\Admin1234\Desktop\1.csv"

         

         

         

        Thank you very much. Best Regards.

    • Luca VALENTINO's avatar
      Luca VALENTINO
      Copper Contributor

       I managed to create the class groups.
      Now I want to insert the members in the various groups but nothing

       

      #Connettere a Teams
      #Connect-MicrosoftTeams
      function Add-Users
      {   
          param(   
                   $ImportPath
                   #,$CurrentUsername,$Role
                )   
          Process
          {
              Import-Module MicrosoftTeams
              $cred = Get-Credential
              $username = $cred.UserName
              Connect-MicrosoftTeams -Credential $cred
              #$teamusers = Import-Csv -Path $ImportPath 
              try{
                      $teamusers = $Users -split ";" 
              Write-Host "Start add the users: " $Users
                      if($teamusers)
                      {
                          for($j =0; $j -le ($teamusers.count - 1) ; $j++)
                          {
                              if($teamusers[$j] -ne $CurrentUsername)
                              {
                                  Add-TeamUser -GroupId $GroupName -User $teamusers[$j]
                              }
                          }
                      }
                  }
              Catch
                  {
                  }
              }
      }
      Add-Users -ImportPath "C:\PC\OFFICE 365\Gruppi_membri_team.csv"

Resources