Teams Admin: Creating Bulk Class Teams using PowerShell and a CSV file

%3CLINGO-SUB%20id%3D%22lingo-sub-1931633%22%20slang%3D%22en-US%22%3ETeams%20Admin%3A%20Creating%20Bulk%20Class%20Teams%20using%20PowerShell%20and%20a%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1931633%22%20slang%3D%22en-US%22%3E%3CP%3EFor%20Your%20Information%3A%20I%20have%20successfully%20created%20Class%20Teams%20using%20PowerShell%20and%20a%20CSV%20file.%20This%20is%20very%20handy%20because%20you%20can%20have%20a%20whole%20list%20of%20teams%2C%20channels%2C%20teachers%20and%20students%20in%20a%20CSV%20file%20making%20creating%20a%20large%20number%20of%20teams%20a%20snap.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20a%20PowerShell%20module%20and%20a%20sample%20CSV%20file.%20The%20method%20is%20similar%20to%20what%20is%20found%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fblog.jijitechnologies.com%2Fcreate-teams-microsoft-teams-powershell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECreate%20teams%20in%20Microsoft%20Teams%20through%20CSV%20using%20PowerShell%20%7C%20JiJi%20Technologies%3C%2FA%3E%2C%20though%20there%20are%20a%20few%20small%20differences.%20I%20did%20not%20write%20the%20script%2C%20I%20found%20it%20online%20-%20but%20I%20cannot%20remember%20where.%20I%20made%20a%20few%20minor%20changes%20where%20the%20original%20script%20gave%20errors.%26nbsp%3B%3CSPAN%3EIn%20the%20spirit%20of%20sharing%2C%20I%20have%20attached%20it%20here.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EBasically%20you%20need%20to%20have%20PowerShell%205.1%20and%20install%20the%20current%20MicrosoftTeams%20PowerShell%20module%20(in%20PowerShell)%20using%20the%20command%26nbsp%3BInstall-Module%20-Name%20MicrosoftTeams%20-RequiredVersion%201.1.6%20(that%20being%20the%20current%20version%20as%20of%20this%20writing).%20You%20need%20to%20run%20PowerShell%20as%20administrator.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EPrepare%20your%20CSV%20file%20using%20the%20example%20I%20have%20attached.%20I%3C%2FSPAN%3E%3CSPAN%3Emport%20the%20PowerShell%20module%20I%20have%20attached%20and%20run%20the%20function%20New-TeamsFromCSV.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EWatch%20your%20computer%20do%20all%20the%20hard%20work%20while%20you%20relax!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2292341%22%20slang%3D%22en-US%22%3ERe%3A%20Teams%20Admin%3A%20Creating%20Bulk%20Class%20Teams%20using%20PowerShell%20and%20a%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292341%22%20slang%3D%22en-US%22%3E%3CP%3ENote%3A%20this%20format%20requires%20you%20to%20give%20the%20path%20to%20the%20CSV%20file%20when%20you%20run%20the%20function%20from%20the%20PowerShell%20command%20line.%20E.g.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ENew-TeamsFromCSV%20c%3A%5Cpowershell%5CNewTeams.csv%20%23substitute%20with%20your%20path%20and%20filename.%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2673341%22%20slang%3D%22en-US%22%3ERe%3A%20Teams%20Admin%3A%20Creating%20Bulk%20Class%20Teams%20using%20PowerShell%20and%20a%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2673341%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F164657%22%20target%3D%22_blank%22%3E%40Marius%20Pretorius%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3Ethank%20you%20for%20your%20excellent%20script%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnforunatelly%20i%20am%20getting%20the%20following%20error%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%20class%3D%22lia-spoiler-container%22%3E%3CA%20class%3D%22lia-spoiler-link%22%20href%3D%22%23%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESpoiler%3C%2FA%3E%3CNOSCRIPT%3E(Highlight%20to%20read)%3C%2FNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-border%22%3E%3CDIV%20class%3D%22lia-spoiler-content%22%3ENew-Team%20%3A%20Error%20occurred%20while%20executing%20Code%3A%20BadRequest%20Message%3A%20Failed%20to%20execute%20Templates%20backend%20request%20CreateTeamFromTemplateRequest.%20Request%20Url%3A%20%3CA%20href%3D%22https%3A%2F%2Fteams.microsoft.com%2Ffabric%2Femea%2Ftemplates%2Fapi%2Fteam%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fteams.microsoft.com%2Ffabric%2Femea%2Ftemplates%2Fapi%2Fteam%3C%2FA%3E%2C%20Request%20Method%3A%20POST%2C%20Response%20Status%20Code%3A%20BadRequest%2C%20Response%20Headers%3A%20Strict-Transport-Security%3A%20max-age%3D2592000%20x-operationid%3A%20e33aa8f7bcaaf2409469a733f43c4d56%20x-telemetryid%3A%2000-e33aa8f7bcaaf2409469a733f43c4d56-2d04028de3c0164f-00%20X-MSEdge-Ref%3A%20Ref%20A%3A%2078BB7E144EAC4317B3AC67C206C16AB8%20Ref%20B%3A%20LON21EDGE1113%20Ref%20C%3A%202021-08-22T15%3A51%3A03Z%20Date%3A%20Sun%2C%2022%20Aug%202021%2015%3A51%3A02%20GMT%20%2C%20ErrorMessage%20%3A%20%7B%22errors%22%3A%5B%7B%22message%22%3A%22Team%20Visibility%20must%20be%20one%20of%20known%20types%3A%20%5BPrivate%2CPublic%2CHiddenMembership%5D.%22%2C%22errorCode%22%3A%22Unknown%22%7D%5D%2C%22operationId%22%3A%22e33aa8f7bcaaf2409469a733f43c4d56%22%7D%20InnerError%3A%20RequestId%3A%20415e5729-033a-4532-b76c-0524e12c9ddd%20DateTimeStamp%3A%202021-08-22T15%3A51%3A03%20HttpStatusCode%3A%20BadRequest%20At%20C%3A%5C365%5Cclasses%5CCreateMsTeamsComprehensive.psm1%3A104%20char%3A30%20%2B%20...%20%24group%20%3D%20New-Team%20-MailNickName%20%24team.TeamsName%20-displayname%20%24tea%20...%20%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%20%2B%20CategoryInfo%20%3A%20SyntaxError%3A%20(Microsoft.Teams...Cmdlets.NewTeam%3ANewTeam)%20%5BNew-Team%5D%2C%20ApiException%20%2B%20FullyQualifiedErrorId%20%3A%20Team%20creation%20failed.%2CMicrosoft.Teams.PowerShell.TeamsCmdlets.NewTeam%3C%2FDIV%3E%3CNOSCRIPT%3E%3CDIV%20class%3D%22lia-spoiler-noscript-container%22%3E%3CDIV%20class%3D%22lia-spoiler-noscript-content%22%3ENew-Team%20%3A%20Error%20occurred%20while%20executing%20Code%3A%20BadRequest%20Message%3A%20Failed%20to%20execute%20Templates%20backend%20request%20CreateTeamFromTemplateRequest.%20Request%20Url%3A%20%3CA%20href%3D%22https%3A%2F%2Fteams.microsoft.com%2Ffabric%2Femea%2Ftemplates%2Fapi%2Fteam%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fteams.microsoft.com%2Ffabric%2Femea%2Ftemplates%2Fapi%2Fteam%3C%2FA%3E%2C%20Request%20Method%3A%20POST%2C%20Response%20Status%20Code%3A%20BadRequest%2C%20Response%20Headers%3A%20Strict-Transport-Security%3A%20max-age%3D2592000%20x-operationid%3A%20e33aa8f7bcaaf2409469a733f43c4d56%20x-telemetryid%3A%2000-e33aa8f7bcaaf2409469a733f43c4d56-2d04028de3c0164f-00%20X-MSEdge-Ref%3A%20Ref%20A%3A%2078BB7E144EAC4317B3AC67C206C16AB8%20Ref%20B%3A%20LON21EDGE1113%20Ref%20C%3A%202021-08-22T15%3A51%3A03Z%20Date%3A%20Sun%2C%2022%20Aug%202021%2015%3A51%3A02%20GMT%20%2C%20ErrorMessage%20%3A%20%7B%22errors%22%3A%5B%7B%22message%22%3A%22Team%20Visibility%20must%20be%20one%20of%20known%20types%3A%20%5BPrivate%2CPublic%2CHiddenMembership%5D.%22%2C%22errorCode%22%3A%22Unknown%22%7D%5D%2C%22operationId%22%3A%22e33aa8f7bcaaf2409469a733f43c4d56%22%7D%20InnerError%3A%20RequestId%3A%20415e5729-033a-4532-b76c-0524e12c9ddd%20DateTimeStamp%3A%202021-08-22T15%3A51%3A03%20HttpStatusCode%3A%20BadRequest%20At%20C%3A%5C365%5Cclasses%5CCreateMsTeamsComprehensive.psm1%3A104%20char%3A30%20%2B%20...%20%24group%20%3D%20New-Team%20-MailNickName%20%24team.TeamsName%20-displayname%20%24tea%20...%20%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%20%2B%20CategoryInfo%20%3A%20SyntaxError%3A%20(Microsoft.Teams...Cmdlets.NewTeam%3ANewTeam)%20%5BNew-Team%5D%2C%20ApiException%20%2B%20FullyQualifiedErrorId%20%3A%20Team%20creation%20failed.%2CMicrosoft.Teams.PowerShell.TeamsCmdlets.NewTeam%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FNOSCRIPT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2680587%22%20slang%3D%22en-US%22%3ERe%3A%20Teams%20Admin%3A%20Creating%20Bulk%20Class%20Teams%20using%20PowerShell%20and%20a%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2680587%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1134513%22%20target%3D%22_blank%22%3E%40Nikos_M%3C%2FA%3E%26nbsp%3B%20Did%20you%20find%20any%20solution%20to%20the%20issue%3F%20I%20ran%20into%20the%20same%20error-message.%3C%2FP%3E%3CP%3ESeems%20like%20we%20have%20to%20add%20a%20Team-Visibility%20Column%20to%20the%20CSV%20file.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2746141%22%20slang%3D%22en-US%22%3ERe%3A%20Teams%20Admin%3A%20Creating%20Bulk%20Class%20Teams%20using%20PowerShell%20and%20a%20CSV%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2746141%22%20slang%3D%22en-US%22%3EHi%2C%20I%20am%20not%20able%20to%20create%20teams%20bulk%20via%20above%20given%20commands%20%2C%20please%20see%20below%20error%20which%20I%20am%20getting%3CBR%20%2F%3E%3CBR%20%2F%3ENew-TeamsFromCSV%20-Path%20%22C%3A%5CUsers%5Cusername%5Cbulkteamscreation.csv%22%3CBR%20%2F%3ENew-TeamsFromCSV%20%3A%20The%20term%20'New-TeamsFromCSV'%20is%20not%20recognized%20as%20the%20name%20of%20a%20cmdlet%2C%20function%2C%20script%20file%2C%20or%20operable%20program.%20Check%20the%20spelling%20of%20the%20name%2C%20or%3CBR%20%2F%3Eif%20a%20path%20was%20included%2C%20verify%20that%20the%20path%20is%20correct%20and%20try%20again.%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20New-TeamsFromCSV%20-Path%20%22C%3A%5CUsers%5Cusername%5Cbulkteamscreation.csv%22%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20ObjectNotFound%3A%20(New-TeamsFromCSV%3AString)%20%5B%5D%2C%20CommandNotFoundException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20CommandNotFoundException%3C%2FLINGO-BODY%3E
Frequent Contributor

For Your Information: I have successfully created Class Teams using PowerShell and a CSV file. This is very handy because you can have a whole list of teams, channels, teachers and students in a CSV file making creating a large number of teams a snap.

 

I have attached a PowerShell module and a sample CSV file. The method is similar to what is found here Create teams in Microsoft Teams through CSV using PowerShell | JiJi Technologies, though there are a few small differences. I did not write the script, I found it online - but I cannot remember where. I made a few minor changes where the original script gave errors. In the spirit of sharing, I have attached it here.

 

Basically you need to have PowerShell 5.1 and install the current MicrosoftTeams PowerShell module (in PowerShell) using the command Install-Module -Name MicrosoftTeams -RequiredVersion 1.1.6 (that being the current version as of this writing). You need to run PowerShell as administrator.

 

Prepare your CSV file using the example I have attached. Import the PowerShell module I have attached and run the function New-TeamsFromCSV.

 

Watch your computer do all the hard work while you relax!

 

4 Replies

Note: this format requires you to give the path to the CSV file when you run the function from the PowerShell command line. E.g.

New-TeamsFromCSV c:\powershell\NewTeams.csv #substitute with your path and filename.

 

@Marius Pretorius 

 

Hi,

thank you for your excellent script

 

Unforunatelly i am getting the following error 

Spoiler
New-Team : Error occurred while executing Code: BadRequest Message: Failed to execute Templates backend request CreateTeamFromTemplateRequest. Request Url: https://teams.microsoft.com/fabric/emea/templates/api/team, Request Method: POST, Response Status Code: BadRequest, Response Headers: Strict-Transport-Security: max-age=2592000 x-operationid: e33aa8f7bcaaf2409469a733f43c4d56 x-telemetryid: 00-e33aa8f7bcaaf2409469a733f43c4d56-2d04028de3c0164f-00 X-MSEdge-Ref: Ref A: 78BB7E144EAC4317B3AC67C206C16AB8 Ref B: LON21EDGE1113 Ref C: 2021-08-22T15:51:03Z Date: Sun, 22 Aug 2021 15:51:02 GMT , ErrorMessage : {"errors":[{"message":"Team Visibility must be one of known types: [Private,Public,HiddenMembership].","errorCode":"Unknown"}],"operationId":"e33aa8f7bcaaf2409469a733f43c4d56"} InnerError: RequestId: 415e5729-033a-4532-b76c-0524e12c9ddd DateTimeStamp: 2021-08-22T15:51:03 HttpStatusCode: BadRequest At C:\365\classes\CreateMsTeamsComprehensive.psm1:104 char:30 + ... $group = New-Team -MailNickName $team.TeamsName -displayname $tea ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SyntaxError: (Microsoft.Teams...Cmdlets.NewTeam:NewTeam) [New-Team], ApiException + FullyQualifiedErrorId : Team creation failed.,Microsoft.Teams.PowerShell.TeamsCmdlets.NewTeam

 

@Nikos_M  Did you find any solution to the issue? I ran into the same error-message.

Seems like we have to add a Team-Visibility Column to the CSV file.

Hi, I am not able to create teams bulk via above given commands , please see below error which I am getting

New-TeamsFromCSV -Path "C:\Users\username\bulkteamscreation.csv"
New-TeamsFromCSV : The term 'New-TeamsFromCSV' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ New-TeamsFromCSV -Path "C:\Users\username\bulkteamscreation.csv"
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-TeamsFromCSV:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException