Mar 21 2020 03:16 AM
I am trying to create Teams from a CSV file
My Csv:
TeamsName | TeamsDescription | Type | TypeTemplate | Owners | |
EV0123 | EV - Prova | Descrizione1 | Private | EDU_Class | email@dom.it |
SN0123 | SN - Prova2 | Descrizione2 | Private | EDU_Class | email@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
Apr 23 2020 09:51 AM
Hi there, i had found a very similar script in another website.
a guy called Andrew West had said in the comments that that the alias and the AccessType should be changed.
Its in: https://www.jijitechnologies.com/blogs/create-teams-microsoft-teams-powershell
Do let us know if your script works with those changes.
Apr 29 2020 10:00 AM
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"
Jun 03 2020 07:38 AM
Hi,
I tried the PowerShell Script method to add Bulk Team users. It worked :)
Nov 25 2020 04:50 AM
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.
TeamsName | TeamType | ChannelName | Owners | Members |
21Accounting11 | EDU_class | Channel1; Channel2 | Teacher1@domain.com | Member1@domain.com; member2@domain.com |
Jan 11 2021 04:08 AM
Good afternoon, thank you for this, its really useful. I will try to emulate to the letter.
This is very kind, thanks again.
Apr 13 2021 07:20 PM
@Marius Pretorius @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.
Apr 26 2021 06:09 AM - edited Apr 26 2021 06:14 AM
Please see my post here (Creating bulk class teams from a CSV file). It has the PowerShell module as well as a sample CSV file.
Apr 26 2021 07:09 AM
It seems your code is missing a function name and opening curly bracket at the beginning and a closing curly bracket below your last line. Your code looks like this:
function Create-Channel
{
..
.
Create-NewTeam -ImportPath "C:\Users\Admin1234\Desktop\1.csv"
It should read like this: (I'm only including the missing code)
Function New-TeamsFromCSV
{
function Create-Channel
.
.
.
Create-NewTeam -ImportPath "C:\Users\Admin1234\Desktop\1.csv"
}
Obviously, you have to take a few steps for your code to execute in PowerShell:
import-module TheModuleName.psm1
New-TeamsFromCSV
Because you are connecting to Teams Admin, you will be asked for your credentials. You need to be a Teams Administrator and provide that username/email address and password. Thereafter you will be flying!
Apr 26 2021 06:30 PM
Good day!
Thank you for your response.... I will definitely study and try your program and instruction...
Cheers!
Best Regards. :)
Apr 26 2021 08:25 PM - edited Apr 26 2021 08:27 PM
Good day!
I already tried your code but this is the error message i've received...
below is the whole code...
----
Function New-TeamsFromCSV
{
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\NewTeams
\NewTeams.csv"
}
May 21 2021 02:41 AM