The estimated reading time 5 minutes
Manage Microsoft Teams with Powershell /ISE (generate teams templates)
Hi everyone,
Lately, I’ve been working more and more with Microsoft teams, so I thought a lot about automating with Powershell. So here’s my first article on MS Teams administration with the help of Powershell.
The aim of this article is to create a team template, which can be reproduced later.
First, the cmdlets must be installed. This can be done very easily. To do this, open a Powershell with administrative rights and enter the following command.
Install-Module MicrosoftTeams -Force
At the moment cmdlets are available in version 0.9.1 which can change rapidly.
If you want to check the installation of the cmdlets you can use the following command.
Get-TeamHelp
Now your ready to connect to office365 tenant with the teams cmdlets.
To do so I created an button in ISE to connect quickly in the future. See my older article in generating a custom button in ISE.
My profile file is customized the following way.
#add msteams commands $parentteams = $psise.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('MS Teams', $null, $null) $parentteams.Submenus.Add(' Start-Teams-Session',{ Invoke-Expression "$env:HOMEPATH\Documents\WindowsPowerShell\msteams\teamsconnection.ps1" }, $null) | Out-Null
So ready to go.
With just one click my ISE is connecting to office365 tenant. Let’s have a look on the script executing with this button.
$tenant = (Connect-MicrosoftTeams) $account = ($tenant.account) $tenantdomain = ($tenant.TenantDomain) $host.ui.RawUI.WindowTitle = "Windows Powershell ISE remote connection to Teams Tenant: $tenantdomain with account $account "
When you click ISE asks for the credentials to office 365.
NOTE: take a user with teams license, otherwise you can not create any teams
After successful login my title in ISE has changed.
We’ve now finished with the basics.
Generating the Templates:
the requirement: when generating a new team, it should have predefinied channels and some security settings (teamtemplate).
To handle the important parameters I use a small csv file where I can write down the information.
Let’s have a look in this csv file.
Line 2 there are the objects within powershell, Line 3 and 4 are two teams which should be generated.
#TYPE Microsoft.TeamsCmdlets.PowerShell.Custom.GetTeam+GetTeamResponse DisplayName,Description,accesstype,alias,channel1,channel2,channel3,channel4,channeldes1,channeldes2,channeldes3,channeldes4 testteam03,created via powershell,public,testteam03,project1,issues,project2,documentation,description for project1,issues never occure,description for project2,place to store all documentation testteam04,created via powershell,public,testteam04,project1,issues,project2,documentation,description for project1,issues never occure,description for project2,place to store all documentation
Now let’s see the corresponding script.
#path to csv file $csvpath = "C:\temp\teams.csv" ################################################### #define permissions for teams (define true or false) no boolean!: # member permission to delete channels within the team $deletechannels = "false" #member permission to create and change channels $createupdatechannels = "false" #member permission to create and update connectors $createconnectors = "false" #member permission to create and change tabs $createtabs = "false" #member permission to add or remove apps $addapps = "false" ################################################### #define allowed fun settings #allow gifs $allowgiphy = "false" $allowstickers = "false" $allowcustmeme = "false" ################################################## #define team guest settings $deletechannelsguest = "false" $createupdatechannelsguest = "false" ################################################## #import information from csv file $importteams = @(Import-Csv -Path "$csvpath" -Encoding UTF8) #generating teams foreach ($team in $importteams){ #get information to variables $displayname = ($team.displayname) $description = ($team.description) $alias = ($team.alias) $accesstype = ($team.accesstype) #creating new team $teamsid = (New-Team -DisplayName "$displayname" -Description "$description" -AccessType "$accesstype" -Alias "$alias") $groupid = ($teamsid.GroupId) # configure member permissions for new team Set-TeamMemberSettings -GroupId $groupid -AllowDeleteChannels $deletechannels -AllowCreateUpdateChannels $createupdatechannels -AllowCreateUpdateRemoveConnectors $createconnectors -AllowCreateUpdateRemoveTabs $createtabs -AllowAddRemoveApps $addapps #configure fun settings Set-TeamFunSettings -GroupId $groupid -AllowGiphy "$allowgiphy" -AllowCustomMemes "$allowcustmeme" -AllowStickersAndMemes "$allowstickers" #configure guest settings Set-TeamGuestSettings -GroupId $groupid -AllowDeleteChannels "$deletechannelsguest" -AllowCreateUpdateChannels "$createupdatechannelsguest" #configure channel-settings for the new team #generate object1 for channelsettings $channelproberties = @() $channelset1 = New-Object PSCustomObject #insert data from csv $channel1 = ($team.channel1) $channelset1 | Add-Member -MemberType NoteProperty -Name ChannelName -Value "$channel1" $channeldes1 = ($team.channeldes1) $channelset1 | Add-Member -MemberType NoteProperty -Name ChannelDescription -Value "$channeldes1" #adding information to object $channelproberties += $channelset1 #generate object 2 for channelsettings $channelset2= New-Object PSCustomObject #insert data from csv $channel2 = ($team.channel2) $channelset2 | Add-Member -MemberType NoteProperty -Name ChannelName -Value "$channel2" $channeldes2 = ($team.channeldes2) $channelset2 | Add-Member -MemberType NoteProperty -Name ChannelDescription -Value "$channeldes2" #adding information to object $channelproberties += $channelset2 #generate object 3 for channelsettings $channelset3= New-Object PSCustomObject #insert data from csv $channel3 = ($team.channel3) $channelset3 | Add-Member -MemberType NoteProperty -Name ChannelName -Value "$channel3" $channeldes3 = ($team.channeldes3) $channelset3 | Add-Member -MemberType NoteProperty -Name ChannelDescription -Value "$channeldes3" #adding information to object $channelproberties += $channelset3 #generate object 4 for channelsettings $channelset4= New-Object PSCustomObject #insert data from csv $channel4 = ($team.channel4) $channelset4 | Add-Member -MemberType NoteProperty -Name ChannelName -Value "$channel4" $channeldes4 = ($team.channeldes4) $channelset4 | Add-Member -MemberType NoteProperty -Name ChannelDescription -Value "$channeldes4" #adding information to object $channelproberties += $channelset4 # generate channels from objects array foreach($channel in $channelproberties){ $channelname = ($channel.channelname) $channeldescritpion = ($channel.channeldescription) New-TeamChannel -GroupId $groupid -DisplayName "$channelname" -Description "$channeldescritpion" | Out-Null } }
This script generates teams really strictly because the security settings where made tight.
The result:
Also security permissions and settings are set.
In the office365 portal you can also see the newly created office365groups.
Last but not least were looking with the powershell in azure ad.
Get-AzureADGroup -SearchString testteam | fl
As mentioned it is also possible to generate a teams template without csv. I thought in this scenario it would be easier.
Comments an feature requests are welcome.
Have fun.
Great tutorial, is it also possible to great the different teams. Like Classes, PLC, Staff Members and Anyone
Hi Eric,
can you explain that a little bit more in detail, please? In my CSV File I’m generating different teams. You can add in csv as much teams as you want.