Microsoft Teams Administration and Management using PowerShell
Microsoft has provided multiple PowerShell commands which you can use for administration and management of your Microsoft Teams; You can do below task using PowerShell Command:
- Teams creation / modification
- Team Channel creation and medication
- Add/ Remove Team member
- Add/ Remove Team Owner
- Get or Set Teams Guest setting
- Set Teams and Set team picture
Available PowerShell commands List:
First see how we can connect to Microsoft Teams PowerShell:
You can save Microsoft Teams PowerShell Module config file to specified location:
Save-Module -Name MicrosoftTeams -Path “C:\temp\”
Once you type “Y” to install NuGet.
Then again run Save-Module -Name MicrosoftTeams -Path Command to save config files stored on below location:
You can directly Install Microsoft Teams module using below command:
Install-Module -Name MicrosoftTeams
Gets warning message to “You are installing the modules from an untrusted repository.” Press “Y” to install Teams
Now Teams Module installed, time to Import Microsoft Teams Module:
PS C:\>Import-Module MicrosoftTeams
PS C:\> $cred = Get-Credential
Supply values for the Credential which as Office 365 Tenant Admin permission.
Then Run below command to Connect MicrosoftTeams
Connect-MicrosoftTeams -Credential $cred
As you already stored type your Office365 Tenant credential in $cred. And now you are able to connect to Microsoft teams. You can use below PowerShell commands.
Note:Currently most of PowerShell Command is in Beta.
- Add-TeamUser:
You can use this command to adds an Teams owner or Teams members to the Teams.
Result will show immediately however it takes some time before changes are reflected. To turn an existing Member into an Owner, first Add-TeamUser -Role Owner -User Bilag to add them to the owners list, then Remove-TeamUser -User Bilag to remove them from the members list.
Add-TeamUser -GroupId -User [-Role ]
Role: Member or Owner
Example:
Add-TeamUser -GroupId 31f1ff6c-d48c-4f8a-b2e1-abca7fd399df -User bilag@mydomain.com -Role Member
How to get GroupID of Teams?
Run below command with your Teams name:
$team = Get-Team | ? {$_.DisplayName -eq "Yourteamname"}
$team.GroupId
- Disconnect-MicrosoftTeams [Cmdlet is in Beta]
Syntax:
Disconnect-MicrosoftTeams [-WhatIf] [-Confirm]
- Get-Team: This command gives all the teams the user is part of. The user must be you - you can only get information on yourself.
Syntax:
Get-Team [-User ]
Example:Get-Team -User bilag@mydomain.com
If user running PowerShell command doesn’t have Teams License assigned, then you cannot run his command so assigns the license and run the same command.
In my case, I assigned Microsoft Teams license to my account, waited for 4-5 minutes to reflect the changes. Run the same command again and see the result.
You cannot run Get-Team command other than your account. It will gives error like below.
- Get-TeamChannel : Get all the channels for a team.
Syntax: Get-TeamChannel -GroupId
Example: Get-TeamChannel -GroupId af55e84c-dc67-4e48-9005-86e0b07272f9
- Get-TeamFunSettings: Gets a Teams function settings.
Syntax: Get-TeamFunSettings -GroupId
Example: Get-TeamFunSettings -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf
- Get-TeamGuestSettings: Gets Team guest settings
Syntax: Get-TeamGuestSettings -GroupId
Example: Get-TeamGuestSettings -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf
- Get-TeamHelp: Gets a list of commands for Microsoft Teams.
Example: Get-TeamHelp
- Get-TeamMemberSettings: Gets team member settings.
Syntax: Get-TeamMemberSettings -GroupId
Example: Get-TeamMemberSettings -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf
- Get-TeamMessagingSettings: Gets team messaging settings.
Syntax: Get-TeamMessagingSettings -GroupId
Example: Get-TeamMessagingSettings -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf
- Get-TeamUser: Returns users of a teams.
Syntax: Get-TeamUser -GroupId [-Role ]
Example: Get-TeamUser -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf -Role Owner
- New-Team: This command will create a new team. The new team will be backed by a new unified group. Creates a new team with user specified settings, and returns a Group object with a GroupID property.
Syntax: New-Team -DisplayName [-Description ] [-Alias ] [-Classification ] [-AccessType ] [-AddCreatorAsMember ]
Example:
New-Team -DisplayName "Tech Reads"
New-Team -DisplayName "Tech Reads" -Description "Team to post technical articles and blogs" -AccessType Public
Connect-MicrosoftTeams -AccountId bilag@mydomain.com
$group = New-Team -alias “TestTeam” -displayname “Test Teams” -AccessType “private”
Add-TeamUser -GroupId $group.GroupId -User "fred@example.com"
Add-TeamUser -GroupId $group.GroupId -User "john@example.com"
Add-TeamUser -GroupId $group.GroupId -User "wilma@example.com"
New-TeamChannel -GroupId $group.GroupId -DisplayName "Q4 planning"
New-TeamChannel -GroupId $group.GroupId -DisplayName "Exec status"
New-TeamChannel -GroupId $group.GroupId -DisplayName "Contracts"
Set-TeamFunSettings -GroupId $group.GroupId -AllowCustomMemes true
Get-MsolGroup -SearchString "TestyTest" | Where-Object DisplayName -eq TestyTest | foreach-object -process {
$name = "TestConvert" + $_.DisplayName
$group = New-Team -displayname $name
Get-MsolGroupMember -GroupObjectId $_.ObjectId | foreach-object -process {
Add-TeamUser -GroupId $group.GroupId -User $_.EmailAddress
}
}
- New-TeamChannel: Add a new channel to a team.
Syntax: New-TeamChannel
-GroupId -DisplayName [-Description ]
Example: New-TeamChannel -GroupId 126b90a5-e65a-4fef-98e3-d9b49f4acf12 -DisplayName "Architecture"
Note:
- Channel display name (DisplayName) must be 50 characters or less, and can't contain the characters # % & * { } / \ : < > ? | '"
- Channel description: Channel description can be up to 1024 characters.
- Remove-Team: This command will allow you to delete a team.
Syntax: Remove-Team -GroupId
Example: Remove-Team -GroupId 31f1ff6c-d48c-4f8a-b2e1-abca7fd399df
- Remove-TeamChannel: This cmdlet will allow you to Delete a channel.
Note:
- This will not delete content in associated tabs.
- The channel will be "soft deleted", meaning the contents are not permanently deleted for a time. So, a subsequent call to Add-TeamChannel using the same channel name will fail if enough time has not passed.
Syntax:
Remove-TeamChannel -GroupId -DisplayName
Example:
Remove-TeamChannel -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf -DisplayName "Tech Reads"
Explanation: -DisplayName : Channel name to be deleted
- Remove-TeamUser: You can use this command to Remove an owner or member from a team, and to the unified group which backs the team.
The command will return immediately, but the Teams application will not reflect the update immediately. The Teams application may need to be open for up to an hour before changes are reflected.
Note: last owner cannot be removed from the team. To turn an existing Member into an Owner, first Add-TeamUser -Role Owner -User foo, then Remove-TeamUser -User foo to remove them from the members list.
Syntax: Remove-TeamUser
-GroupId -User
Example:
Remove-TeamUser -GroupId 31f1ff6c-d48c-4f8a-b2e1-abca7fd399df -User bilag@mydomain.com
- Set-Team: Updates a Teams and Teams setting.
Set-Team
-GroupId [-DisplayName ] [-Description ]
[-Alias ] [-Classification ] [-AccessType ]
Example:
Set-Team -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf -DisplayName "Updated TeamName" -AccessType Public
- -AccessType: Team access type. Valid values are "Private" and "Public"
- -Alias: Same as displayName without any spaces. Team Alias Characters Limit - 64
- -Classification : Team classification.
- -DisplayName: Team display name. Team Name Characters Limit - 256.
- -Description: Team description. Team Description Characters Limit - 1024.
- Set-TeamChannel: Update Team channels settings.
Syntax:
Set-TeamChannel -GroupId -CurrentDisplayName
[-NewDisplayName ] [-Description ]
Example:
Set-TeamChannel -GroupId c58566a6-4bb4-4221-98d4-47677dbdbef6 -CurrentDisplayName TechReads -NewDisplayName "Technical Reads"
Set-TeamChannel -GroupId c58566a6-4bb4-4221-98d4-47677dbdbef6 -CurrentDisplayName TechReads -NewDisplayName "Technical Reads"
- -NewDisplayName: New Channel display name. Names must be 50 characters or less, and can't contain the characters # % & * { } / \ : < > ? | '"
- -Description: Updated Channel description. Channel Description Characters Limit - 1024.
- Remove-TeamUser:
This cmdlet is currently in Beta. Remove an owner or member from a team, and to the unified group which backs the team. Note: the command will return immediately, but the Teams application will not reflect the update immediately. The Teams application may need to be open for up to an hour before changes are reflected. Note: last owner cannot be removed from the team. To turn an existing Member into an Owner, first Add-TeamUser -Role Owner -User foo, then Remove-TeamUser -User foo to remove them from the members list.
Syntax:
Remove-TeamUser -GroupId -User
Example: Remove-TeamUser -GroupId 31f1ff6c-d48c-4f8a-b2e1-abca7fd399df -User dmx@example.com
- Set-Team: Updates a team.
Syntax:
Set-Team -GroupId [-DisplayName ] [-Description ]
[-Alias ] [-Classification ] [-AccessType ]
Example: Set-Team -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf -DisplayName "Updated TeamName" -AccessType Public
- -GroupId: GroupId of the
- -AccessType: Team access type. Valid values are "Private" and "Public"
- -Alias: Same as displayName without any spaces. Team Alias Characters Limit - 64
- -Classification: Team classification
- -Description: Team description. Team Description Characters Limit - 1024.
- -DisplayName: Team display name. Team Name Characters Limit - 256.
- Set-TeamChannel: Update Team channels settings.
Syntax:
Set-TeamChannel -GroupId -CurrentDisplayName
[-NewDisplayName ] [-Description ]
Example: Set-TeamChannel -GroupId c58566a6-4bb4-4221-98d4-47677dbdbef6 -CurrentDisplayName TechReads -NewDisplayName "Technical Reads"
- -CurrentDisplayName: Current channel name
- -GroupId: GroupId of the team
- -Description: Updated Channel description. Channel Description Characters Limit - 1024.
- -NewDisplayName: New Channel display name. Names must be 50 characters or less, and can't contain the characters # % & * { } / \ : < > ?
- Set-TeamFunSettings: Update Giphy, Stickers and Memes settings.
Syntax:
Set-TeamFunSettings -GroupId [-AllowGiphy ]
[-GiphyContentRating ] [-AllowStickersAndMemes ]
[-AllowCustomMemes ]
Example: Set-TeamFunSettings -GroupId 0ebb500c-f5f3-44dd-b155-cc8c4f383e2d -AllowGiphy true -GiphyContentRating Strict
- -GroupId: GroupId of the team
- -AllowCustomMemes: Allow custom memes to be uploaded
- -AllowGiphy: Setting to enable giphy for team
- -AllowStickersAndMemes: Enable Stickers and memes
- -GiphyContentRating: Settings to set content rating for giphy. Can be "Strict" or "Moderate"
- Set-TeamGuestSettings: Updates team guest settings.
Syntax:
Set-TeamGuestSettings -GroupId [-AllowCreateUpdateChannels ] [-AllowDeleteChannels ]
Example: Set-TeamGuestSettings -GroupId a61f5a96-a0cf-43db-a7c8-cec05f8a8fc4 -AllowCreateUpdateChannels true
- -GroupId: GroupId of the team
- -AllowCreateUpdateChannels: Settings to create and update channels
- -AllowDeleteChannels: Settings to Delete channels
- Set-TeamMemberSettings: Updates team member settings.
Syntax:
Set-TeamMemberSettings -GroupId [-AllowCreateUpdateChannels ] [-AllowDeleteChannels ] [-AllowAddRemoveApps ] [-AllowCreateUpdateRemoveTabs ] [-AllowCreateUpdateRemoveConnectors ]
Example: Set-TeamMemberSettings -GroupId 4ba546e6-e28d-4645-8cc1-d3575ef9d266 -AllowCreateUpdateChannels false
Set-TeamMemberSettings -GroupId 4ba546e6-e28d-4645-8cc1-d3575ef9d266 -AllowDeleteChannels true -AllowAddRemoveApps false
- -GroupId: GroupId of the team
- -AllowAddRemoveApps: Setting to add and remove apps to teams
- -AllowCreateUpdateChannels: Setting to create and update channels
- -AllowCreateUpdateRemoveConnectors: Setting to create, update and remove connectors
- -AllowCreateUpdateRemoveTabs:Setting to create, update and remove tabs
- -AllowDeleteChannels: Setting to Delete channels
- Set-TeamMessagingSettings: Updates team messaging settings.
Syntax:
Set-TeamMessagingSettings -GroupId [-AllowUserEditMessages ] [-AllowUserDeleteMessages ] [-AllowOwnerDeleteMessages ] [-AllowTeamMentions ] [-AllowChannelMentions ]
Example:
Set-TeamMessagingSettings -GroupId 4ba546e6-e28d-4645-8cc1-d3575ef9d266 -AllowUserEditMessages true
Set-TeamMessagingSettings -GroupId 4ba546e6-e28d-4645-8cc1-d3575ef9d266 -AllowUserDeleteMessages false -AllowChannelMentions true
- -GroupId: GroupId of the team
- -AllowChannelMentions: Allow @channel or @[channel name] mentions. This wil notify members who've favorited that channel
- -AllowOwnerDeleteMessages: Setting to allow owner to Delete messages
- -AllowTeamMentions: Allow @team or @[team name] mentions. This will notify everyone in the team.
- -AllowUserDeleteMessages: Setting to allow user to delete messages.
- -AllowUserEditMessages: Setting to allow user to edit messages
- Set-TeamPicture: Update the team picture. Note: the command will return immediately, but the Teams application will not reflect the update immediately. The Teams application may need to be open for up to an hour before changes are reflected.
Syntax: Set-TeamPicture -GroupId -ImagePath
Example:
Set-TeamPicture -GroupId 2f162b0e-36d2-4e15-8ba3-ba229cecdccf -ImagePath c:\Image\TeamPictire.png
-GroupId: GroupId of the team
-ImagePath: File path and image (.png,.gif, *.jpg, or *.jpeg)
Thank you.