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 ...
Install-Module -Name MicrosoftTeams
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 inGet-TeamHelp
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:
New-Team
Set-Team
Remove-Team
Get-Team
New-Team
Add-teamuser
Remove-teamuser
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.