For those of you who have been trying to automate anything related to Microsoft Teams, let me tell you that there is a new PowerShell Module in town: Microsoft Teams 0.9.0 which you can install with the following command:
1 Install-Module MicrosoftTeams
Now to automate the channel creation In A Team you can simply:
Create a file createTeamChannel.ps1 with the following contents:
1 Param
2 (
3 [Parameter(Mandatory = $true)][string]$username,
4 [Parameter(Mandatory = $true)][securestring]$password,
5 [Parameter(Mandatory = $true)][string]$tenantId,
6 [Parameter(Mandatory = $true)][string]$teamName,
7 [Parameter(Mandatory = $true)][string]$channelName)
8
9 # Create PSCredential
10 $credential = New-Object System.Management.Automation.PSCredential($username, $password)
11
12 # Connect to Microsoft Teams
13 Connect-MicrosoftTeams -TenantId $tenantId -Credential $credential
14
15 # Get the Team
16 $team = Get-Team | Where-Object { $_.DisplayName -eq $teamName}
17
18 if ($team) {
19 # Create the new Team Channel
20 New-TeamChannel -GroupId $team.GroupId -DisplayName $channelName -Description $channelName
21 }
22 else {
23 throw "Team: $teamName does not exist."
24 }
Run the following command in PowerShell
1 $password = ConvertTo-SecureString "YOUR PASSWORD" -AsPlainText -Force
2 .\createTeamChannel.ps1 username@tenant.com $password $tenantId MonitoringIssues Incident101
Hope it helps!
Comments