Microsoft Teams helps people in the organization to communicate and share files with people inside and outside the organization. Microsoft Teams usage has increased a lot in this remote situation. It results in the demand of managing Microsoft Teams by Administrators. Admins can either use Teams admin center or PowerShell to manage their Teams environment. But most admins prefer PowerShell due to its flexibility and operation speed. If you are new to PowerShell or Office 365, it is really challenging to identify the right cmdlet.
So, we are here to help you. This blog lists the top 10 cmdlets to manage the Microsoft Teams environment using PowerShell. Before using the Teams PowerShell cmdlets, you must install and connect to Microsoft Teams PowerShell module.
You must be either a global administrator or Teams administrator to run the below Teams PowerShell cmdlets.
Create and Manage Teams using PowerShell:
You can create a new team using the New-Team cmdlet. For example,
New-Team –DisplayName <TeamName>
When you create a team, it automatically creates Office 365 unified group, SharePoint site, and Planner in the backend.
To get a list of teams in your organization, you can use the ‘Get-Team’ cmdlet.
To change settings in teams, run the ‘Set-Team’ cmdlet with the properties to be updated.
Set-Team -GroupId <TeamId> -Description "Teams description updated" -Visibility "Public"
In the above example, the team’s description and visibility are updated.
Add Members to Team:
To add users to a specific team, use the ‘Add-TeamUser’ cmdlet as shown below.
Add-TeamUser -GroupId <TeamId> -User <UPN>
If you want to add a user as an owner, run the above cmdlet along with the ‘Role’ parameter.
Add-TeamUser -GroupId <TeamId> -User <UPN> -Role Owner
Remove Users from Teams:
To remove an owner or member from a team, you can use the ‘Remove-TeamUser’ cmdlet.
To remove a member from the team, run the following cmdlet.
Remove-TeamUser –GroupId <team’s groupid> -User <MemberUPN>
When you want to remove the owner from a group, first change their role from owner to member, then remove them. Because when you remove the owner from a team, they will stay as a member. For example,
To remove John, who is the owner of a Project Team, run the following script.
Remove-TeamUser –GroupId <ProjectTeam’s id> -User [email protected] -Role Owner #Removed from owner role in Project Team.
Remove-TeamUser –GroupId <ProjectTeam’s id> -User [email protected] #Removed from Project Team
The first example will remove the user from owner role in Project Team and second example remove the user from Project Team.
To get a report on teams, channels, and their members/owners, you can download the Teams reporting using PowerShell script from o365reports.com.
Create Channel in Teams:
After creating a team, you can create channels under that team using the ‘New-TeamChannel’ cmdlet using the following syntax.
New-TeamChannel -GroupId <Team’s groupid> -DisplayName <ChannelName>
The above format creates a standard channel. To create a private channel, run the above code with the ‘MembershipType’ parameter.
New-TeamChannel -GroupId 126b90a5-e65a-4fef-98e3-d9b49f4acf12 -DisplayName "Confidential" -MembershipType Private
This example creates a private channel called ‘Confidential’.
Add Members to Teams Private Channel:
To add members or owners to a private channel, you can use the ‘Add-TeamChannelUser’ cmdlet. To add a user as a member, run the following code.
Add-TeamChannelUser –GroupId <TeamId> -DisplayName <PrivateChannelName> -User <UPN>
To promote a user as owner, execute the below cmdlet.
Add-TeamChannelUser –GroupId <TeamId> -DisplayName <PrivateChannelName> -User <UPN> -Role <Owner>
Remove Members from Private Channel:
You can use the ‘Remove-TeamChannelUser’ cmdlet to remove a user from the private channel or demote the existing owner into a member. When you want to remove the owners from a private channel, you first demote them to members, then remove them.
To demote an owner to a member, run the following cmdlet.
Remove-TeamChannelUser –GroupId <team’s groupid> -User <OwnerUPN> -Role Owner
To remove a member from the private channel, execute the below code.
Remove-TeamChannelUser –GroupId <team’s groupid> -User <MemberUPN>
Download the private channel reporting script to know about the private channels in your organization and their membership details.
When a team is no longer active but wants to keep the content accessible, you can archive it using the ‘Set-TeamArchivedState’. You can also reactivate the archived teams if needed.
To archive a specific team,
Set-TeamArchivedState –GroupId <Team id> -Archived $true
To unarchive a team, run the Set-TeamArchivedState cmdlet with Archived as False. For example,
Set-TeamArchivedState –GroupId <Team id> -Archived $false
You can refer the manage archives in teams blog to know more about archiving teams in bulk and retrieving all the archived teams.
Delete Teams and Channels:
To delete a team, run the ‘Remove-Team’ cmdlet with the team’s groupid as shown below.
Remove-Team –GroupId <team’s groupid>
To delete a channel in a team, run the ‘Remove-TeamChannel’ cmdlet with team identity and channel name.
Remove-TeamChannel –GroupId <team’s groupid> - DisplayName <ChannelName>
I hope this blog will be handy in managing the Microsoft Teams Environment using the command line. Isn’t it helpful? Share your thoughts in the comment section.