Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Teams Policy assignment - deploy-classteams.ps1
Jakob Schaefer
This script was designed to deploy standardized Teams for Courses.
You have to build a CSV as a Source for this script should look like:
With this input a seperate Teams will be created for every Course in a Class
Every Teacher will be assigned as a Teams Owner
Students that have filled the Azure AD Department Field = Classname will be assigned to the created team as a member
Path to the csv that contains classes, teachers and courses
.\deploy-classteams.ps1 -csv Classes.csv
$teamstoDeploy=Import-Csv $CSV -Delimiter ';'
Write-Host -ForegroundColor Gray -Object "ACTION: Please authenticate as an Teams Admin"
Write-Host -ForegroundColor Gray -Object "ACTION: Please authenticate as an Azure AD Admin"
foreach ($entry in $teamstoDeploy){
Write-Host -ForegroundColor Gray -Object "INFO: Start creation of Teams for Class $($entry.ClassName) "
Write-Host -ForegroundColor Gray -Object "----------------------------------------------------------------------------------------"
foreach ($cours in $courses){
try {
$courseTeam=new-team -MailNickName ($entry.ClassName+"_"+$cours) -DisplayName ($entry.ClassName+" "+$cours) -Owner $teachers[0] -Template "EDU_Class" -ErrorAction Stop
Write-Host -ForegroundColor Gray -Object "INFO: A Team with the name $($courseTeam.Displayname) was created successfully, the first owner is $($teachers[0])"
#now add other teachers as owners
try {
do {
Add-TeamUser -GroupID $courseTeam.GroupID -User $teachers[$i] -Role Owner -ErrorAction Stop
Write-Host -ForegroundColor Gray -Object "INFO: The teacher $($teachers[$i]) has beed added to the team"
} until ($i -le $teachers.count)
catch {
Write-Host -ForegroundColor Red -Object "ERROR: The teacher $($teachers[$i]) couldn´t be addad as a Owner. Please add him manually"
#now add students
$Students = Get-AzureADUser -Filter "$StudentFilterAttribute eq '$($entry.ClassName)'"
foreach ($student in $students){
$addedstudents+=Add-TeamUser -GroupID $courseTeam.GroupID -User $Student.ObjectID -Role Member
catch {
Write-Host -ForegroundColor Red -Object "ERROR: The team with the name $($courseTeam.Displayname) couldn´t be created. Please check the CSV/Teams for duplicates or invalid characters"
Write-Host -ForegroundColor Gray -Object "INFO: The creation of Teams for $($entry.ClassName) is finished"
Write-Host -ForegroundColor Gray -Object "----------------------------------------------------------------------------------------"
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 5. in line 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment