Forum Discussion
Create Teams from csv
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.
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.
- wardt9May 21, 2021Copper ContributorThanks for this, it worked well, the only issue I ran into is that I needed to update my MicrosoftTeams Powershell Module to the latest version. Prior to that then it would run successfully once per day but then after that, fail with an error about MS Graph backend. Anyway, the update resolved this. So thanks again!