Microsoft Teams usage has increased greatly during the current pandemic. All types of organizations are using the communications tool to stay connected with its employees and customers alike. The increase of use has also resulted in an increase of demand of system administrator's time to manage Microsoft Teams. Everything from adding users and groups to managing policies of said users and groups can be managed via PowerShell. This post will highlight the foundations to get started and provide links to continue your automation through script writing journey.
Let's begin ...
Step 1: Getting started
- Launch PowerShell and run the following command
Install-Module -Name MicrosoftTeams
- With the Microsoft Teams cmdlet installed, use the following to login into your Microsoft Teams tenant
Connect-MicrosoftTeams
Note: This will also work if multi-factor authentication is enabled and you will be asked for your Office 365 credentials to sign in
- Use the following command to see a list of available Microsoft Teams cmdlets
Get-TeamHelp
Step 2: Choose your MS Teams cmdlet adventure
There is a plethora of cmdlets available as listed by the previous step. Here is a list of the cmdlets you will use most often:
- Creates a new Team
New-Team
- Team properties management
Set-Team
- Erases a Team
Remove-Team
- Lists team objects with properties
Get-Team
- Creates a new Team
New-Team
- Adds a user to a team
Add-teamuser
- Removes a user from a team
Remove-teamuser
There is a great deal more as mentioned and all cmdlets can be found in the Microsoft Teams cmdlet reference document.
Step 3: Managing Microsoft Teams policies
Policies within Microsoft Teams govern over a user's or team's abilities within teams and channels. Policies can enforce on behalf of a single user or an entire organization. The automation that PowerShell provides allow the Microsoft Teams administrator the ability to assign custom policies to multiple users as required.
In this example, the following script assigns the Human Resources Management Policy to all users in the Human Resources group. The script begins by getting the GroupObjectId of the group. Once acquired, it then finds the members of that group and assigns the policy to all users in the group.
$group = Get-AzureADGroup -SearchString "Human Resources group" $members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true | Where-Object {$_.ObjectType -eq "User"}$members | ForEach-Object { Grant-CsTeamsChannelsPolicy -PolicyName "Human Resources Management Policy" -Identity $_.UserPrincipalName}
As always, please share your comments below on bettering the above script or any questions you may have.