How to Manage Microsoft Teams via PowerShell
Published Aug 20 2020 12:01 AM 58.8K Views
Microsoft

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
 

  1. Launch PowerShell and run the following command
    Install-Module -Name MicrosoftTeams
     
  2. 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
     
  3.  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.

 

12 Comments
Copper Contributor

Great article. One thing I would recommend is not to do this in a large involvement. It takes a very long time to Iterate over each user and apply the policy. For anything with 50-100+ I would recommend the new-csbatchpolicyassignment commandlet. Much faster. I was able to do 700 in 3 min. The other way look 2 hours and eventually timed out session.



Microsoft

 

The term 'Get-TeamHelp' is not recognized as the name of a cmdlet

 

 

Do you know how to resolve this issue? I ran the first two commands smoothly.

Copper Contributor

I assume it was really meant to be 'Get-Help Team'

Microsoft

@geothing and @QingchuanZhang what is listed there is correct: Get-TeamHelp

Bronze Contributor

Get-TeamHelp doesn't work!

Copper Contributor

Why not just use Get-Command -Module MIcrosoftTeams ?

Copper Contributor

I tried running Get-TeamHelp and it did not work for me either. Running Get-Command -Module MicrosoftTeams as suggested by Jhochwald did not list Get-TeamHelp as a valid command, but did show all of the valid MS Teams cmdlets. Also you could also do Get-Help *Team* to pull a list of Teams cmdlets. Just be ready to sift through some NIC Teaming cmdlets. I have to concur with what everyone else is saying that Get-TeamHelp is not a valid cmdlet.

Copper Contributor

@RichShivers at least the Version 1.1.6 doesn't have the Get-TeamHelp command.

I also check the File list on the PowerShell Gallery.

Steel Contributor

Useful article.

Thanks @Anthony Bartolo.

Bronze Contributor

Hi @Anthony Bartolo 

Just played with Teams PS and hit to pretty odd issue. When I have more than one SIP port on our PSTN Gateway, the Teams PS module does not allow us to use more than one port. This is because PS module forces the "identity" and "fqdn" on New-CsOnlinePSTNGateway to be the same, as the documentation says also: 

"When creating a new SBC, the identity must be identical to the -FQDN parameter, described above. If the parameter is not defined the Identity will be copied from the -FQDN parameter. The Identity parameter is not mandatory."

This leads me to the issue that I cannot have multiple identities where ports are different.

 

The correct way for this is to remove requirement to have identity and fqdn identical. And let us to defines the identity for example:

New-CsOnlinePSTNGateway -identity "country 5063" -Fqdn sbc1.contoso.com -port 5063

New-CsOnlinePSTNGateway -identity "country 5064" -Fqdn sbc1.contoso.com -port 5064

 

Copper Contributor

Any recommendations to bulk enable Guardian notifications for a set of Class Teams?
With 800 classes, we're keen to ensure that guardians notifications are sent out for specific classes (not looking to set for all) without having to direct all teachers on how to do this. Guardians is turned on in SDS

Copper Contributor

the right cmdlet is : Get-help team

 

MuyisDavies1830_0-1702054369270.png

 

Co-Authors
Version history
Last update:
‎Apr 27 2021 07:26 AM
Updated by: