Manage your Teams on Microsoft Teams

Microsoft Teams have been a great Modern Workspace collaboration tool due to the diversity and how easy is to use. Creating a new Team is pretty easy and that can encourage to create teams for everything. Controlling your teams can be challenging. In the article, we will get a report from your Teams on your Organization.


With the combination of Excel and Microsoft Teams PowerShell, we can understand more about our teams. This script will list all the Teams as well as the Team Owners, Members and Guest. You can check the Teams cmdlet on the next link.

To install the PowerShell of Microsoft Teams, run the Microsoft PowerShell as Administrator and insert the command below, more information to manual install on the next link.

Install-Module -Name MicrosoftTeams

Connect-MicrosoftTeams 

$excel = New-Object -ComObject Excel.Application
$excel.Visible = $True 
Add-Type -AssemblyName Microsoft.Office.Interop.Excel

$teams = Get-Team
$worksheet = $excel.Workbooks.Add()

$worksheet.ActiveSheet.Name = "Teams"
$worksheet = $excel.Worksheets.Item(1)

$worksheet.Cells.Item(1,1) = "Name of Team"
$worksheet.Cells.Item(1,2) = "Description of Team"
$worksheet.Cells.Item(1,3) = "Group ID"
$worksheet.Cells.Item(1,4) = "Team Tab"

$Cell = $worksheet.UsedRange
$Cell.Interior.ColorIndex = 19
$Cell.Font.ColorIndex = 11
$Cell.Font.Bold = $True

$teamTab = 1
$row = 2

foreach($team in $teams){

 $worksheet.Cells.Item($row , 1) = $team.DisplayName
 $worksheet.Cells.Item($row , 2) = $team.Description
 $worksheet.Cells.Item($row , 3) = $team.GroupId	
 $worksheet.Cells.Item($row , 4) = "Team Tab " + $teamTab
 
 $row += 1
 $teamTab+= 1
}
foreach($team in $teams){
 $worksheet = $excel.Worksheets.Add()
 
 $worksheet.Cells.Item(1,1) = "Team Owners"
 $worksheet.Cells.Item(1,2) = "Team Members"
 $worksheet.Cells.Item(1,3) = "Team Guest"
 
 $Cell = $worksheet.UsedRange
 $Cell.Interior.ColorIndex = 19
 $Cell.Font.ColorIndex = 11
 $Cell.Font.Bold = $True
 
 $rowMembers = 2
 $rowOwners = 2
 $rowGuest = 2
 
 $teamUsers = Get-TeamUser -GroupId $team.GroupId	
 foreach($teamUser in $teamUsers){
  if($teamUser.Role -match "owner"){
   $worksheet.Cells.Item($rowOwners, 1) = $teamUser.User
   $rowOwners += 1 
  }
  if($teamUser.Role -match "member"){
   $worksheet.Cells.Item($rowMembers, 2) = $teamUser.User
   $rowMembers += 1 
  }
  if($teamUser.Role -match "guest"){
   $worksheet.Cells.Item($rowGuest, 3) = $teamUser.User.Split("#EXT#")[0]
   $rowGuest += 1 
  }	
 }
}

Conclusion


After you run the PowerShell, you will get a report on an Excel file which will help you to understand your Teams. Below is a Gif with the final result of the Script.

One Comment

  1. Joe Moore said:

    Very useful script. Thanks!

    March 18, 2019
    Reply

Leave a Reply

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