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.

  1. Open Windows PowerShell with “Run as Administrator”, and Enter
    Install-Module -Name MicrosoftTeams
  2. 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 = ""
$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
Add-TeamUserThe ‘Add-TeamUser’ adds an owner or member to the team, and to the unified group which backs the team.
Connect-MicrosoftTeamsThe 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-MicrosoftTeamsDisconnects from the Microsoft Teams environment
Get-CsPolicyPackageThis cmdlet supports retrieving all the policy packages available on a tenant.
Get-CsUserPolicyPackageThis cmdlet supports retrieving the policy package that’s assigned to a user.
Get-CsUserPolicyPackageRecommendationThis cmdlet supports retrieving recommendations for which policy packages are best suited for a given user.
Get-TeamThis 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-TeamChannelGet all the channels for a team.
Get-TeamsAppReturns app information from the Teams tenant app store.
Get-TeamUserReturns users of a team.
Grant-CsUserPolicyPackageThis 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-CsBatchPolicyPackageAssignmentOperationThis 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-TeamThis cmdlet lets you provision a new Team for use in Microsoft Teams and will create an O365 Unified Group to back the team.
New-TeamChannelAdd a new channel to a team.
New-TeamsAppCreates a new app in the Teams tenant app store.
Remove-TeamThis cmdlet deletes a specified Team from Microsoft Teams.
Remove-TeamChannelDelete a channel. This will not delete content in associated tabs.
Remove-TeamsAppRemoves an app in the Teams tenant app store.
Remove-TeamUserRemove an owner or member from a team, and from the unified group which backs the team.
Set-TeamThis cmdlet allows you to update properties of a team, including its displayname, description, and team-specific settings.
Set-TeamArchivedStateThis 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-TeamChannelUpdate Team channels settings.
Set-TeamsAppUpdates 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. By following the steps outlined in this guide, you should now be able to connect to Microsoft Teams and use the available cmdlets to manage teams and channels, retrieve user and team information, and perform other tasks. This can help you to improve the management of Microsoft Teams in your organization, as well as automate routine tasks, and gather insights on the usage of Microsoft Team.

You can automate a lot many tasks in your Microsoft Teams. Here is my related post on managing Microsoft Teams using PowerShell: How to Manage Microsoft Teams using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

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

  • Hi!
    How can I send a message to a person using this?

  • 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!

      • Yes, with MFA environment, Just a simple command Connect-MicrosoftTeams and should bring up the login screen then you have to authenticate via app or text, whatever you’re setup in MFA setting. You should be good.


Leave a Reply

Your email address will not be published. Required fields are marked *