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, and it can be used for real-time communication, sharing files, managing projects, and more. As Microsoft Teams is a crucial part of the communications strategy in most organizations, the combination of 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 basic commands you can use once connected. Let’s get started!

Connect to Microsoft Teams using PowerShell

Connecting to Microsoft Teams using PowerShell is simple and straightforward. To connect to Microsoft Teams using PowerShell, you will need to first install the Microsoft Teams PowerShell module. This module can be installed from the PowerShell Gallery by running the following command: Install-Module -Name MicrosoftTeams. Once the module has been installed, you will need to connect to your Microsoft Teams account by running the Connect-MicrosoftTeams cmdlet. This cmdlet will prompt you for your Microsoft Teams credentials, and once you have entered them, you will be connected to your Microsoft Teams account. From there, you can use all of the cmdlets in the MicrosoftTeams module to manage your Microsoft Teams environment.

Step 1: Install Microsoft Teams PowerShell Module

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

Get-module *teams* 

This gets you the installed Teams modules along with its version.

check teams powershell module is instaled

This gets you the Microsoft Teams PowerShell version.

How do I get the Microsoft Teams PowerShell module? If the Teams module is 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.

How do I update Microsoft Teams PowerShell module?

To upgrade the teams module, run:

Update-Module MicrosoftTeams

Step 2: Connect to Microsoft Teams using PowerShell

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


You’ll get a popup to enter your credentials. This Popup is multi-factor authentication (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 username and password to 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! Here is the PowerShell script to connect with the username and password in the script.

#Import the Microsoft Teams module
Import-Module -Name MicrosoftTeams

#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

Disconnect Microsoft Teams from PowerShell

To disconnect the Microsoft Teams environment from PowerShell, run the cmdlet:


Get All PowerShell Cmdlets available in Teams Module

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

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

Although the Microsoft 365 admin center can be used to administer various Microsoft 365 services like Azure AD, Teams, SharePoint Online, and Exchange Online, PowerShell provides more flexibility and additional capabilities that help Admins to save a lot of time and effort. You can automate a lot many tasks in your Microsoft Teams. Of course, PowerShell makes it easy to manage Teams! Here is my related post on managing Microsoft Teams using PowerShell: How to Manage Microsoft Teams using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

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

  • Doing so, you can’t run an automated script.
    I can do this in AzureAd – Connect-AzureAD -AccountId $UPNAccount
    But in Teams this fails –
    Connect-MicrosoftTeams -Credential $UPNAccount
    Connect-MicrosoftTeams : Cannot bind parameter ‘Credential’. Cannot convert the “upn-account” value of type “System.String” to type “System.Management.Automation.PSCredential”.

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

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

      • Thanks, That worked!


Leave a Reply

Your email address will not be published.