As an administrator, you might need to work with Microsoft Teams using PowerShell. In this tutorial, I will show you how to connect to Teams from PowerShell with some real examples.
You can use the Microsoft Teams PowerShell module to manage teams directly from the PowerShell command line.
But before that, you need to install the Microsoft Teams PowerShell module.
Install Microsoft Teams PowerShell Module
Note: Microsoft Teams PowerShell module supports with Windows PowerShell 5.1 or PowerShell 7.2 or later. Additionally, you need to install .NET Framework 4.7.2 or later.
Then run the below PowerShell cmdlet to install the Microsoft Teams PowerShell module.
Install-Module -Name MicrosoftTeams -Force

You can also install it offline by downloading it from here.
To update the Teams PowerShell module, run the following command.
Update-Module MicrosoftTeams
To uninstall the Teams PowerShell module, run the following cmdlet.
Uninstall-Module MicrosoftTeams
or
Uninstall-Module MicrosoftTeams -AllVersions
If you want to disconnect Microsoft Teams in PowerShell, then run the command below:
Disconnect-MicrosoftTeams
Connect to Microsoft Teams from PowerShell
Once the installation is successful, we will see how to connect to Microsoft Teams from the PowerShell command line.
For this, Microsoft provides Connect-MicrosoftTeams cmdlets.
$credential = Get-Credential
Connect-MicrosoftTeams -Credential $credential
When you run the above commands, it will ask you to enter the credentials. Ensure that you provide the admin credentials for Microsoft Teams.
Then it will connect.
This is how to connect to Microsoft Teams using PowerShell using the Connect-MicrosoftTeams PowerShell cmdlets.
Read: How to create a team in Microsoft Teams
Microsoft Teams PowerShell Commands Examples
Now, let me show you some examples. We will see how to work with teams from PowerShell command line.
1. Create Teams in Microsoft Teams using PowerShell
Below is the PowerShell command to create a team in Microsoft Teams using PowerShell. We can use the New-Team PowerShell cmdlets.
New-Team -DisplayName "Weekend Trip" -Description "This is team for the trip" -Visibility Public
This will create a public team, where anyone from your organization can join. If you want to create a private team, set the Visibility to Private.
The below PowerShell command will create a new team in Microsoft Teams, add a user to the team, and then create a channel in the team.
$group = New-Team -MailNickname "HRTeam" -displayname "HR Team" -Visibility Public
Add-TeamUser -GroupId $group.GroupId -User "user1@tsinfotechnologies.onmicrosoft.com"
New-TeamChannel -GroupId $group.GroupId -DisplayName "HR USA"

Once the Teams PowerShell command is executed successfully, you will see the team has been created with the member and channel in Microsoft Teams.

2. Get the GroupId of the Team in Microsoft Teams using PowerShell
To do any PowerShell operation in a Team in Microsoft Teams, we need to have the GroupId. Below is the PowerShell command we can use to get group id from Teams Display name.
The command below will return the Group ID, Display name, visibility, Description, etc.
Get-Team -DisplayName "TestingTeam"
We can also run the following command.
$team=Get-Team -DisplayName "TestingTeam"
$team.GroupId
3. Add a User to a Team using PowerShell
Now, let us see how to add a user to a team using PowerShell in Microsoft Teams.
Microsoft provides the Add-TeamUser PowerShell command that we can use to add an owner or a member to a Microsoft team.
Add-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -User user1@tsinfotechnologies.onmicrosoft.com
Once you execute the command, you can see that the user will be added to the Team.

To add a user as the owner of a team in Microsoft Teams using PowerShell, use the -Role parameter with a value of Owner. Below is the example.
Add-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -User Bhawana@tsinfotechnologies.onmicrosoft.com -Role Owner

4. PowerShell get-team
Let us see how to get a list of all Microsoft Teams PowerShell.
Below is the PowerShell command that will retrieve all teams from Microsoft Teams.
Get-Team
It will return the following properties:
- GroupId
- DisplayName
- Visibility
- Archived
- MailNickName
- Description

Similarly, if you want to get team details based on the Display Name then run the below command:
Get-Team -DisplayName "Testing Team"
If you want to display team details based on the MailNickName, run the PowerShell commands below.
Get-Team -MailNickName "TestingTeam"
5. Get all teams a user is a member of
Let us see how to get all teams a user is a member of using PowerShell. Below is the PowerShell cmdlet:
Get-Team -User user1@tsinfotechnologies.onmicrosoft.com
This will give all the teams the user belongs to in Microsoft Teams using PowerShell.
6. Create a Channel in Teams PowerShell
Let us see another Microsoft Teams PowerShell example, how to create a channel in Microsoft Teams using PowerShell.
Microsoft provides the New-TeamChannel PowerShell cmdlet to create a channel for a specific team in Microsoft Teams.
Here we need to get the groupid. Follow the above example to get the group ID of a particular team.
New-TeamChannel -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -DisplayName "USA Testing Team"

If you want to create a private channel, then pass the parameter as, -MembershipType Private, it looks like below:
New-TeamChannel -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -DisplayName "USA Testing Team" -MembershipType Private
This is how to add a channel to a team using PowerShell.
7. PowerShell get all teams users
Let us see how to get all team users in PowerShell.
Microsoft provides the Get-TeamUser PowerShell cmdlet to retrieve users of a specific team in Microsoft Teams.
Below is the PowerShell command that will give all the users of a particular Microsoft team. It includes both owners and members.
Get-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7
If you want to retrieve only the owners, then run the below command (Pass the -Role Owner as a parameter):
Get-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -Role Owner
If you want to retrieve only the members, then run the below command (Pass the -Role Member as a parameter):
Get-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -Role Member
If you want to retrieve only the Guests, then run the below command (Pass the -Role Guest as a parameter):
Get-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -Role Guest
You can see the output.

8. Get all Teams and Owners using PowerShell
Here is another interesting example of Microsoft Teams PowerShell. Here, we will see how to get all teams and corresponding owners using PowerShell in Microsoft Teams.
A team can have more than one owner, so run the PowerShell script below to retrieve all teams and their corresponding team owners in a proper format.
$allTeams=Get-Team
# Loop through the teams
foreach($team in $allTeams)
{
$allOwners= Get-TeamUser -GroupId $team.GroupId -Role Owner
"`n" + "Team Name: " + $team.DisplayName
foreach($owner in $allOwners)
{
Write-Host "User: " $owner.User " Name: " $owner.Name
}
}
You can see the output.

This is how to get all the teams and owners in Microsoft Teams using PowerShell.
9. Get all Teams and Channels using PowerShell
How to get all teams and channels using PowerShell in Teams? To get all the teams and corresponding channels using PowerShell in Microsoft Teams, we can use the Get-TeamChannel PowerShell cmdlets.
A team can have one or more channels in Microsoft Teams. In the code below, we first retrieve all the teams and then apply a foreach loop to get all the channels for a particular Team using PowerShell.
$allTeams=Get-Team
foreach($team in $allTeams)
{
$allChannel = Get-TeamChannel -groupid $team.groupid
"`n" + "Team Name: " + $team.DisplayName
foreach($channel in $allChannel)
{
Write-Host "Channel Name: " $channel.DisplayName
}
}

To retrieve the channels from a specific team, run the following PowerShell command.
Get-TeamChannel -groupid 59eda95a-0664-4860-9a51-2f4ff60e0cb7
The above PowerShell cmdlet will return all the channels for a particular team in Microsoft Teams.
10. Add Channels to Team from CSV file using PowerShell
Now, let us see how to add channels to a team from a CSV file using PowerShell in Microsoft Teams. Here I have a CSV file that has one column as Name and contains a few records.

Below is the PowerShell cmdlet to add bulk channels to a Microsoft Teams using PowerShell.
Import-csv D:\Bijay\Channels.csv | foreach{New-TeamChannel -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -DisplayName $_.Name}

This way, we can add a bulk channel to a Microsoft Team from a CSV file using PowerShell.
Also, check out Microsoft Teams Tips and Tricks
11. Create teams PowerShell csv
Let us see now how to create teams using PowerShell from a CSV file. The below PowerShell script will help you create teams in bulk.
Here I have a .csv file with some Team names.
Import-csv D:\Bijay\Teams.csv | foreach{New-Team -DisplayName $_.Name}
You can see it created like below:

If you open the Microsoft Teams desktop app, you will be able to see all the teams created successfully from the .CSV file.

This is how to create teams in bulk from a csv file using PowerShell.
12. Delete Teams using PowerShell
Now, let us see how to delete a team using PowerShell.
Microsoft Teams provides the Remove-Team PowerShell cmdlets to delete a particular team using PowerShell.
Remove-Team -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7
If you want to remove teams in bulk using PowerShell, follow the PowerShell script below. Here, I have used the same .csv file.
Import-csv D:\Bijay\Teams.csv | foreach{
$team=Get-Team -DisplayName $_.Name
Remove-Team -GroupId $team.GroupId
}
It will delete all teams that are present in the .csv file.
13. Add Guest User to Teams using PowerShell
Now, let us see how to add guest users to teams using PowerShell. Run the below PowerShell command to add a guest user to a team in Microsoft Teams.
Add-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -User yourguestuseremailid@gmail.com -Role Member
Here, if the guest user is not added to the Azure Active Directory then you will get an error like below:
Add-TeamUser : Error occurred while executing
Code: Request_ResourceNotFound
Message: Resource ‘fewlines4biju@gmail.com’ does not exist or one of its queried reference-property objects are not present.
InnerError:
RequestId: 36aed36d-d7de-43c5-b0ff-aee9111e7a24
DateTimeStamp: 2021-06-23T12:55:58
HttpStatusCode: Request_ResourceNotFound
At line:1 char:1
- Add-TeamUser -GroupId 59eda95a-0664-4860-9a51-2f4ff60e0cb7 -User fewl …
~~~~~~~~~~~~~~~~~- CategoryInfo : NotSpecified: (:) [Add-TeamUser], ApiException
- FullyQualifiedErrorId : Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException,Microsoft.TeamsCmdlets.PowerShell.Custom.AddT
eamUser

To fix this issue, check if the user is in the Guest users list in the Microsoft 365 admin center.
Open the Microsoft 365 admin center, expand Users -> Guest users, and the user should be there in the Guest users list.

If the user is not presented here, then the error will occur. And if the user is there, then the error will not come, and the guest user will be added to teams.
If you want to add bulk guest users in Azure AD, then follow this article.
This is how to add a guest user to Teams using PowerShell.
In this tutorial, I explained how to connect to Microsoft Teams using PowerShell with a few examples. Do let me know in the comments below if these examples help you.
You may also like the following tutorials:
- Create Group in Teams
- Add External User to Teams
- Microsoft Teams Language Settings
- Create a Private Channel in Teams

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.