May 26, 2022

Samir Daoudi's Technical Blog

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

Export all Microsoft Teams Members and Owners to a CSV File using PowerShell

In this script, we will look at exporting all Microsoft Teams’ Owners and Members to a CSV file.

This extract might help to communicate with all the owners, in my previous example, we had to send a notification to all the owners, telling them that the teams will be switched from Public to Private.

 

List all the teams’ owners and memebrs

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 = "./All Teams Members and Owner Report_$((Get-Date -format yyyy-MMM-dd-ddd` hh-mm` tt).ToString()).csv"
Write-Host Exporting all Teams members and owners report...
$Count = 0
Get-Team | foreach {
    $TeamName = $_.DisplayName
    Write-Progress -Activity "`n     Processed Teams count: $Count "`n"  Currently Processing: $TeamName"
    $Count++
    $GroupId = $_.GroupId
    Get-TeamUser -GroupId $GroupId | foreach {
        $Name = $_.Name
        $MemberMail = $_.User
        $Role = $_.Role
        $Result = @{'Teams Name' = $TeamName; 'Member Name' = $Name; 'Member Mail' = $MemberMail; 'Role' = $Role }
        $Results = New-Object psobject -Property $Result
        $Results | select 'Teams Name', 'Member Name', 'Member Mail', 'Role' | 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: