Use PowerShell to create a Microsoft Teams Channel
Use PowerShell to create a Microsoft Teams Channel
Categories:
less than a minute
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:
Install-Module MicrosoftTeams
Now to automate the channel creation In A Team you can simply:
Create a file createTeamChannel.ps1 with the following contents:
Param
(
[Parameter(Mandatory = $true)][string]$username,
[Parameter(Mandatory = $true)][securestring]$password,
[Parameter(Mandatory = $true)][string]$tenantId,
[Parameter(Mandatory = $true)][string]$teamName,
[Parameter(Mandatory = $true)][string]$channelName)
# Create PSCredential
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
# Connect to Microsoft Teams
Connect-MicrosoftTeams -TenantId $tenantId -Credential $credential
# Get the Team
$team = Get-Team | Where-Object { $_.DisplayName -eq $teamName}
if ($team) {
# Create the new Team Channel
New-TeamChannel -GroupId $team.GroupId -DisplayName $channelName -Description $channelName
}
else {
throw "Team: $teamName does not exist."
}
Run the following command in PowerShell
$password = ConvertTo-SecureString "YOUR PASSWORD" -AsPlainText -Force
.\createTeamChannel.ps1 username@tenant.com $password $tenantId MonitoringIssues Incident101
Hope it helps!