Jump to content

Recommended Posts

Posted

Hi

 

In their ultimate wisdom, Microsoft seems to have removed the cmdlet to assign templates to the Microsoft teams module and it was only available in a preview.

 

We are wanting to create teams from an CSV file and set them as an EDU_Class, giving the team, the assignments and class notebook tabs. Has anyone a workaround or know which previous version had this included.

 

This is the code we are trying to use

 

#Creating Microsoft teams using .csv
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.TeamsName -displayname $team.TeamsName  -Template $team.Template
               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:\CreateTeams\NewTeams.csv"

Posted (edited)

I actually came across this recently myself. The latest version that included the Template parameter is 0.9.6 (They removed it in the 1.0 release). You can install it via:

 

Install-Module -Name MicrosoftTeams -RequiredVersion 0.9.6

 

and then import that version via:

 

Import-Module MicrosoftTeams -RequiredVersion 0.9.6

 

However in that version of the module the New-Team cmdlet doesn't have the MailNickname parameter as in your example, it's instead called Alias

Edited by fordea
  • Thanks 1
  • 3 weeks later...
  • 1 month later...
Posted
hmm yeah interesting that they have removed some of the functionality when they come out of the beta module, I can see why and this is down to the graph API version that is used in the background. I would say try your hand at using PowerShell and graph API calls to create and manage your teams, and when possible try to use the GUIDS that represent your users as this offers some big performance improvements.
Posted

I've just stuck with 0.9.6 for my scripts as it seems to do everything I need (and still has the Template parameter).

 

You do need to be careful when writing code for this - especially if what you are doing is New-Team, then a loop around Add-TeamUser as when the back end is busy it'll just throw an Exception "429 Too many requests" and you end up with the team and half the users added. Something like doing each step within a try/catch and adding a 5 second sleep if it hits that error before trying again is usually enough to get round it (although a couple of weeks ago I couldn't do more than 2 Teams based cmdlets without a 60 second pause before the next)

Posted (edited)

That error there @Katy is you hitting your tenant wide limit for calls into the graph API service. You should look at trapping the http response retry-after and backing off your requests until the time specified. This will get you back more quickly than a sleep because if you hit the service again it adds toward your limit even if no action is taken due to you being throttled.

 

Again something that you can handle better if you leverage the underlying graph API, I would like to know what you are doing to hit the throttle limit as I bet we hit the service a lot more than most.

 

In fact this here will give you better guidance:-

https://docs.microsoft.com/en-us/graph/throttling

Edited by HPlum78
Posted
Ah just seen that the beta endpoint has had its limits altered so that may explain why you are hitting the throttle limits using the 0.9.6 module.
Posted
Ah just seen that the beta endpoint has had its limits altered so that may explain why you are hitting the throttle limits using the 0.9.6 module.

It was stopping me from running more than 1 cmdlet every 10 minutes at one point - definitely not down to the tenancy limit, this was when everyone in the world was rushing to create teams. I've made 12 new teams and populated them yesterday (with the "sleep" line commented out) and it worked fine.

Posted (edited)

Yeah @Katy during the initial push to lock down I recall MS saying that they added ~88K servers to the teams infrastructure (from memory) the provisioning issue using the beta endpoints was due to them squeezing that beta api service resource wise and giving it to the production api service (they do cover that off in the service offering documentation for the api service) so those that leverage the beta service could/ would have hit provisioning stalls due to resource constraints. Don't forget that the teams service is not the same as the service that you hit when you are provisioning your teams you are hitting the graph API service.

 

I will point you guys at the link below, as I will reiterate if you can leverage the graph API directly (not just for your trams work) then you will unlock a load of goodness.... I know that this is a little more dev than just using the PS commands but you have already chosen to use PS so using the graph API is just the next step and is just a next step in using PowerShell to automate the world.

 

https://docs.microsoft.com/en-us/graph/teams-concept-overview

Edited by HPlum78
Posted (edited)

@pvalentim so I have took a real quick look at the code you are using and a couple of things spring to mind (I am not answering your question directly re 17 users then stopping)

 

I am an advocate of try/ catch blocks, these are important especially if you are taking an action (so try{ ipmo teams } catch{ write-log-error failed to import module}) the problem with the code that you have posted is that you have try/ catch blocks but are not doing anything in the catch. You need to catch whatever happens/ does not happen in try else you may as well not have the try/ catch block in the first instance.

 

The next thing that sticks out is one thing I wish could be un-invented write-host, the whole reason to script is so that you can fire and forget or schedule it to run write-host has no use when you start using scripts like that "in space no one can hear you scream" comes to mind. Good for a dirty way to debug but outside of that it should be cast from your scripts. (I will point you at Don Jones tweet him write-host and see how he replies, he and Jeff Snover have had some interesting and lively debates on this over the years :-P). I have posted a function on these forums in the past that essentually allows you to log info/ warnings and errors and will out them to the screen (if being run interactively) or to a file, you should use something like that in the catch parts of your try/ catch blocks. This may well give you some insights into why only 17 users are being added to your teams (So I may have answered you question indirectly).

 

One other thing, this is another around script automation and that is $cred = Get-Credential nothing wrong with this outside of automation but when you come to automation that needs addressing, I will post some of my thoughts and options around how you can deal with credentials in scripts.

Edited by HPlum78

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...