May 26, 2022

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

List all Microsoft Teams using PowerShell

Last week, I have been faced with a serious issue for which I had to act very quickly.

A typical SharePoint search started showing content from different teams, which have been all set as public teams.

A direct result of quickly jumping into using Teams due to the current pandemic and the need for remote work enabling, without enough time to think about Teams Governance or the security aspect of the content.

I am sure, this is the case of many organisations.

The problem was to find all the public teams and quickly lock them down to private teams and private channels.

Doing this via the Teams Admin portal would have taken days, so I had to write a PowerShell Script to first list all the public teams, then switch them to private after internal review.

 

List all the teams

Requirements

The following PowerShell script requires the following:

  1. Microsoft Teams module for powershell  available from:
    1. Install the Microsoft Teams PowerShell module via PowerShell Gallery(recommended option).
    2. Install the Microsoft Teams PowerShell module via Manual Download.
  2. Having Teams or Tenant admin rights.

Once these two requirements were in place, time for the action:

The Script

 

$Result = ""  
$Results = @() 
$Path = "./Teams Report_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
Write-Host Exporting all Teams report...
$Count = 0
Get-Team | foreach {
    $TeamName = $_.DisplayName
    Write-Progress -Activity "`n     Processed Teams count: $Count "`n"  Currently Processing: $TeamName"
    $Count++
    $Visibility = $_.Visibility
    $MailNickName = $_.MailNickName
    $Description = $_.Description
    $Archived = $_.Archived
    $GroupId = $_.GroupId
    $ChannelCount = (Get-TeamChannel -GroupId $GroupId).count
    $TeamUser = Get-TeamUser -GroupId $GroupId
    $TeamMemberCount = $TeamUser.Count
    $TeamOwnerCount = ($TeamUser | ? { $_.role -eq "Owner" }).count
    $Result = @{'Teams Name' = $TeamName; 'Team Type' = $Visibility; 'Mail Nick Name' = $MailNickName; 'Description' = $Description; 'Archived Status' = $Archived; 'Channel Count' = $ChannelCount; 'Team Members Count' = $TeamMemberCount; 'Team Owners Count' = $TeamOwnerCount }
    $Results = New-Object psobject -Property $Result
    $Results | select 'Teams Name', 'Team Type', 'Mail Nick Name', 'Description', 'Archived Status', 'Channel Count', 'Team Members Count', 'Team Owners Count' | Export-Csv $Path -NoTypeInformation -Append
}
Write-Progress -Activity "`n     Processed Teams count: $Count "`n"  Currently Processing: $TeamName" -Completed
if ((Test-Path -Path $Path) -eq "True") {
    Write-Host `nReport available in $Path -ForegroundColor Green
}

 

Leave a comment

You may have missed

Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: