With Microsoft Teams being as popular as it is now, it is even more important for administrators to manage it effectively. Microsoft Teams provides a PowerShell module available for install using the following command:
Install-Module MicrosoftTeams
Import-Module MicrosoftTeams
You can, however, use the Microsoft Graph PowerShell instead to perform many of the same administration tasks. You can find the documentation here:
https://docs.microsoft.com/en-us/powershell/module/microsoft.graph.teams/?view=graph-powershell-beta
As always, to install the Microsoft Graph PowerShell modules, you can use these commands:
Install-Module Microsoft.Graph
Select-MgProfile -Name "beta"
Import-Module Microsoft.Graph
Next, you need to connect to the Microsoft Graph with the specific scopes or permissions for managing Microsoft Teams.
$scopes = @(
"TeamsApp.ReadWrite.All",
"TeamsAppInstallation.ReadWriteForTeam",
"TeamsAppInstallation.ReadWriteSelfForTeam",
"TeamSettings.ReadWrite.All",
"TeamsTab.ReadWrite.All",
"TeamMember.ReadWrite.All",
"Group.ReadWrite.All",
"GroupMember.ReadWrite.All"
)
Connect-MgGraph -Scopes $scopes
Once connected, you can start to execute commands. For these examples to work, I have already retrieved the Team ID using other PowerShell.
$object = Get-Team -DisplayName "SOC Team"
Some examples are below:
NOTE: No comments on the use or lack of use of backticks, splatting, or class instantiation either; it is just for layout on the post 🙂
View Microsoft Team Details
$team = Get-MgTeam -TeamID $object.GroupId
$team | Select-Object *
View Microsoft Team Channels
$channels = Get-MgTeamChannel -TeamId $object.GroupId
$channels | Select-Object *
View Microsoft Team Members
$members = Get-MgTeamMember -TeamId $object.GroupId
$members | Select-Object *
Create a New Microsoft Team
$teamname = "PowerShell Team"
$teamdescription = "PowerShell Team Description"
$teamvisibility = "public"
$funSettings = @{
"allowGiphy" = "false";
"giphyContentRating" = "strict";
"allowStickersAndMemes" = "false";
"allowCustomMemes" = "false";
}
$memberSettings = @{
"allowCreateUpdateChannels" = "true";
"allowCreatePrivateChannels" = "false";
"allowDeleteChannels" = "true";
"allowAddRemoveApps" = "false";
"allowCreateUpdateRemoveTabs" = "false";
"allowCreateUpdateRemoveConnectors" = "false";
}
$guestSettings = @{
"allowCreateUpdateChannels" = "false";
"allowDeleteChannels" = "false";
}
$messagingSettings = @{
"allowUserEditMessages" = "true";
"allowUserDeleteMessages" = "true" ;
"allowOwnerDeleteMessages" = "false";
"allowTeamMentions" = "false";
"allowChannelMentions" = "false";
}
Using Namespace Microsoft.Graph.PowerShell.Models
[MicrosoftGraphTeam1]@{
Template = [MicrosoftGraphTeamsTemplate]@{
Id = 'com.microsoft.teams.template.OrganizeHelpDesk'
}
DisplayName = $teamname
Description = $teamdescription
FunSettings = $funSettings
GuestSettings = $guestSettings
MessagingSettings = $messagingSettings
MemberSettings = $memberSettings
Visibility = $teamvisibility
} | New-MgTeam
Update a Microsoft Team
$funSettings = @{ `
"allowGiphy" = "true"; `
"giphyContentRating" = "moderate"; `
"allowStickersAndMemes" = "true"; `
"allowCustomMemes" = "true"; `
}
Update-MgTeam `
-TeamId $object.GroupId `
-FunSettings $funSettings
Add a Teams Channel
$channelname = "Commands"
$channeldescription = "Channel for Suggested Commands"
$channel = New-MgTeamChannel `
-TeamId $object.GroupId `
-DisplayName $channelname `
-Description $channeldescription
Update Teams Channel
$channelname = "Cmdlets"
$channeldescription = "Channel for Suggested Cmdlets"
Update-MgTeamChannel `
-ChannelId $channel.Id `
-TeamId $object.GroupId `
-DisplayName $channelname `
-Description $channeldescription
Add a Teams Owner and Member
$owneruser = "adelev@M365x.OnMicrosoft.com"
$ownerteamuser = Get-MgUser `
-UserId $user
$ownerproperties = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember";
"user@odata.bind" = "https://graph.microsoft.com/beta/users/" + $ownerteamuser.Id
}
$role = "owner"
New-MgTeamMember `
-TeamId $object.GroupId `
-Roles $role `
-AdditionalProperties $ownerproperties
$memberuser = "adelev@M365x.OnMicrosoft.com"
$memberteamuser = Get-MgUser `
-UserId $user
$memberproperties = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember";
"user@odata.bind" = "https://graph.microsoft.com/beta/users/" + $memberteamuser.Id
}
$role = "member"
New-MgTeamMember `
-TeamId $object.GroupId `
-Roles $role `
-AdditionalProperties $memberproperties
Archive and Unarchive a Team
Invoke-MgArchiveTeam `
-TeamId $object.GroupId
Invoke-MgUnarchiveTeam `
-TeamId $object.GroupId
There are many more commands available; however, you will need to spend time within the Graph Explorer checking each command to ensure what format is required and if it will function as expected.
As the documentation updates, examples will be available to help in executing all of the commands.
You must log in to post a comment.