How to Connect to Microsoft Teams with PowerShell?

Requirement: Connect to Microsoft Teams using PowerShell.

Microsoft Teams is a platform for team collaboration in the workplace. It can be used for real-time communication, sharing files, managing projects, and more. As PowerShell provides a powerful way to automate tasks, In this post, I’ll walk you through how to connect to Microsoft Teams using PowerShell. We’ll also see some of the basic commands you can use once you’re connected. Let’s get started!

Step 1: Install Microsoft Teams PowerShell Module

To start with, you need to install the PowerShell module for Microsoft Teams. Check if you have teams module installed already by: 

Get-module *teams* 
check teams powershell module is instaled

This gets you the Microsoft Teams PowerShell version. If it’s not installed already, Here is how to install the Microsoft Teams PowerShell module.

  • Open Windows PowerShell with “Run as Administrator”, and Enter
    Install-Module -Name MicrosoftTeams
  • Confirm the prompt by entering “A” Yes to All. The module will start to download and install.

Update Teams Module: To update the teams module, run:

Update-Module MicrosoftTeams

Step 2: Connect to Microsoft Teams using PowerShell

Once you have the Teams PowerShell module is installed, you can connect to Teams using 

Connect-MicrosoftTeams

You’ll get a popup to enter your credentials. This Popup is MFA aware! You can connect Microsoft Teams PowerShell with MFA by leaving the “-Credential” parameter.

connect to microsoft teams with powershell

You can also use the credential parameter to get the credentials and connect.

#Connect to Microsoft Teams
Connect-MicrosoftTeams -Credential (Get-Credential)

Can I connect to Microsoft Teams with a hard-coded user name and password through PowerShell? Sure!

#Parameters for Credentials
$UserName = "[email protected]"
$PassWord = ConvertTo-SecureString -String "Password goes here" -AsPlainText -Force

#Create a Credential object
$Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $UserName, $PassWord

#Connect to Microsoft Teams with given user name and password
Connect-MicrosoftTeams -Credential $Cred

#Get All Public Teams
Get-Team | Where {$_.Visibility -eq "Public"}

Make sure you have either global administrator or Teams service administrator rights before connecting to teams. Although any team owner/member can connect to Teams with PowerShell, their permissions are limited within the teams.

Step 3: Start using Cmdlets for Microsoft Teams

Once you have established the connectivity with Microsoft Teams, you can start using PowerShell cmdlets. E.g., Let’s get a list of Microsoft Teams using PowerShell

#Connect to Microsoft Teams
Connect-MicrosoftTeams -Credential (Get-Credential)

#Get all Teams
Get-Team

Disconnect Microsoft Teams from PowerShell

Disconnect-MicrosoftTeams

Get All PowerShell Cmdlets available in Teams Module

To get all available cmdlets for Teams, you can use:

Get-Command -Module MicrosoftTeams
Name Description
Add-TeamUser The `Add-TeamUser` adds an owner or member to the team, and to the unified group which backs the team.
Connect-MicrosoftTeams The Connect-MicrosoftTeams cmdlet connects an authenticated account to use for Microsoft Teams cmdlet requests. You can use this authenticated account only with Microsoft Teams cmdlets.
Disconnect-MicrosoftTeams Disconnects from the Microsoft Teams environment
Get-CsPolicyPackage This cmdlet supports retrieving all the policy packages available on a tenant.
Get-CsUserPolicyPackage This cmdlet supports retrieving the policy package that’s assigned to a user.
Get-CsUserPolicyPackageRecommendation This cmdlet supports retrieving recommendations for which policy packages are best suited for a given user.
Get-Team This cmdlet supports retrieving teams with particular properties/information, including all teams that a specific user belongs to, all teams that have been archived, all teams with a specific display name, or all teams in the organization.
Get-TeamChannel Get all the channels for a team.
Get-TeamsApp Returns app information from the Teams tenant app store.
Get-TeamUser Returns users of a team.
Grant-CsUserPolicyPackage This cmdlet supports applying a policy package to users in a tenant. Note that there is a limit of 20 users you can apply the package to at a time.
New-CsBatchPolicyPackageAssignmentOperation This cmdlet submits an operation that applies a policy package to a batch of users in a tenant. A batch may contain up to 5000 users.
New-Team This cmdlet lets you provision a new Team for use in Microsoft Teams and will create an O365 Unified Group to back the team.
New-TeamChannel Add a new channel to a team.
New-TeamsApp Creates a new app in the Teams tenant app store.
Remove-Team This cmdlet deletes a specified Team from Microsoft Teams.
Remove-TeamChannel Delete a channel. This will not delete content in associated tabs.
Remove-TeamsApp Removes an app in the Teams tenant app store.
Remove-TeamUser Remove an owner or member from a team, and from the unified group which backs the team.
Set-Team This cmdlet allows you to update properties of a team, including its displayname, description, and team-specific settings.
Set-TeamArchivedState This cmdlet is used to freeze all of the team activity, but Teams Administrators and team owners will still be able to add or remove members and update roles
Set-TeamChannel Update Team channels settings.
Set-TeamsApp Updates an app in the Teams tenant app store.

How to uninstall Microsoft Teams PowerShell?

For some reason, If you want to uninstall the Microsoft Teams PowerShell module, use:

UnInstall-Module MicrosoftTeams

Here is my related post, How to Manage Microsoft Teams using PowerShell?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “How to Connect to Microsoft Teams with PowerShell?

  • Do we have a way of using the Connect-MicrosoftTeams with MFA ? if so someone want to share some info?

    Reply
    • Just use “Connect-MicrosoftTeams” without -Credential parameter. You’ll get a login popup – which is MFA aware!

      Reply

Leave a Reply