{
"$type": "site.standard.document",
"content": "---\ntitle: \"Bulk-add students to MS Teams from a csv file\"\ndescription: \"A PowerShell snippet for bulk-adding students to an MS Teams class from a CSV\n of email addresses---works on macOS and Linux too.\"\ntags:\n - dev\n---\n\n[My institution](https://anu.edu.au) now uses\n[MS Teams](https://teams.microsoft.com) for lots of things, including organising\nclasses & communicating with students. It's not perfect, but it's not terrible,\nand the pros & cons of Teams as a pedagogical platform are best left for another\npost.\n\nThis post is about one particular pain point in every lecturer's workflow: even\nthough we're using MS Teams for class communication, it doesn't integrate with\nour enrolment databases. This means that to add all the enrolled students into\nthe class's Teams site you can either:\n\n- add them manually, one-at-a-time, through the Teams app; or\n\n- share the \"join Team\" link on some other communication channel and manually\n weed out the gatecrashers\n\n:::tip\n\nToo much manual work---**there's gotta be a better way**.\n\n:::\n\nMS Teams doesn't have a UI button for \"add team members from\n[csv file](https://en.wikipedia.org/wiki/Comma-separated_values)\". The app _is_\nscriptable, but only via a\n[PowerShell module](https://docs.microsoft.com/en-au/MicrosoftTeams/teams-powershell-overview).\nSo, I (& others[^brent]) came up with a snippet of\n[PowerShell](https://github.com/powershell/powershell) code for bulk-adding\nstudents to a Team from a csv file.\n\nThe only requirements are:\n\n1. you can run PowerShell on your machine\n\n2. the Team already exists (and you know the Team name)\n\n3. you've got a csv file which contains a column (with the heading `email`)\n which contains each student's email address\n\n[^brent]: shout out to Brent Schuetze who first figured this out\n\n## PowerShell script\n\n```powershell\n# install the Teams module (if you haven't already)\n# this only needs to be done once\nInstall-Module -Name MicrosoftTeams\nGet-Module -ListAvailable -Name MicrosoftTeams\n\n# this step will take you to a login page in your browser,\n# you need to sign in to authorise your PowerShell session\nConnect-MicrosoftTeams\n\n# store the team's GroupID into a variable\n# replace \"My Team Name\" with the name of your team\n$GroupID = (Get-Team -DisplayName \"My Team Name\").GroupID\n\n# note: if you've used a different csv filename, change it in the command below\nImport-Csv -Path emails.csv | foreach {Add-TeamUser -GroupId $GroupID -user $_.email}\n```\n\nWhen you're dealing with 500+ student classes, this can save you a _lot_ of\ntime. And since trying to add a student who's already a group member is a no-op,\nyou can just re-run the script with an updated `emails.csv` file if the class\nlist changes. This won't remove students who have unenrolled, but there's a\n`Remove-TeamUser` command as well---so changing the script to unenroll students\nfrom a csv file is pretty trivial.\n\nIf you're worriedly thinking \"that'd be awesome... if I used Windows\", then I\nhave some good news: while PowerShell is primarily a Microsoft thing, it's on\nmacOS and Linux as well. On my macOS machine I installed it through\n[homebrew](https://brew.sh) with:\n\n```plaintext\nbrew install powershell\n```\n\nFrom the [PowerShell README.md](https://github.com/powershell/powershell) it\nseems like there's a package available for most Linux distros as well.\n",
"createdAt": "2026-05-13T23:14:51.707Z",
"description": "A PowerShell snippet for bulk-adding students to an MS Teams class from a CSV of email addresses---works on macOS and Linux too.",
"path": "/blog/2021/04/01/bulk-add-students-to-ms-teams-from-a-csv-file",
"publishedAt": "2021-04-01T00:00:00.000Z",
"site": "at://did:plc:tevykrhi4kibtsipzci76d76/site.standard.publication/self",
"tags": [
"dev"
],
"textContent": "A PowerShell snippet for bulk-adding students to an MS Teams class from a CSV of email addresses---works on macOS and Linux too.",
"title": "Bulk-add students to MS Teams from a csv file"
}