Skip to content

Instantly share code, notes, and snippets.

@guillaumemeyer
Last active December 1, 2025 10:50
Show Gist options
  • Select an option

  • Save guillaumemeyer/fe4ed1b818c5d99eabff1c792a366f71 to your computer and use it in GitHub Desktop.

Select an option

Save guillaumemeyer/fe4ed1b818c5d99eabff1c792a366f71 to your computer and use it in GitHub Desktop.
Exports the owners and members of a Microsoft Teams team as a CSV file
// ****************************************************************************************************************************
// Abstract:
// This script is just a quick hack to export the owners and members of a team as a CSV file without administrator permissions.
//
// Usage:
// 1. Open your team
// 2. Select "Manage team" from its menu
// 3. Select the "Members" tab
// 4. Expand the "Owners" and "Members and guests" sections
// 5. Make sure to scroll down to the end of the owners and members lists to include all of them in your export (As the members are loaded on demand)
// 6. Open your browser console
// 7. Copy and paste all the content of this script to the console and type "Enter"
// 8. The CSV file download should start automatically
//
// ToDo:
// - Parse tags to include them in the export
// ****************************************************************************************************************************
$(function() {
// **************
// Initialization
// **************
const csvFileName = 'team-membership-roster-export.csv'
const csvDelimiter = ','
const csvHeader = 'Display Name' + csvDelimiter + 'Title' + csvDelimiter + 'Location' + csvDelimiter + 'Role' + csvDelimiter + 'UPN' + '\r\n' // CSV header row
let csvContent = csvHeader // Initialize CSV content
const rosterLength = $('.td-member-display-name').length // Number of visible members
// Check if we're an owner of the team
let roleSelector = '.td-member-role' // Consider we're not an owner by default
if ($('.td-member-editable-role').length > 0) {
roleSelector = '.td-member-editable-role' // Override if we're an owner
}
// ************************
// Iterate over each member
// ************************
for (let index = 0; index < rosterLength; index++) {
// Extract the display name, title, location and role
const displayName = $('.td-member-display-name').eq(index).text()
const title = $('.td-member-title').eq(index).text()
const location = $('.td-member-location').eq(index).text()
const role = $(roleSelector).eq(index).text()
const upn = $('.td-member-photo img').eq(index).attr('upn')
// Append to the CSV content
const csvRow = displayName + csvDelimiter + title + csvDelimiter + location + csvDelimiter + role + csvDelimiter + upn + '\r\n'
csvContent += csvRow
}
// Debug the export to console
console.info(rosterLength + ' members exported:')
console.info(csvContent)
// **********************************************************
// Dynamically generates a CSV file and triggers its download
// **********************************************************
// Create a dynamic "a" tag
var element = document.createElement('a')
// Set href link with content
element.setAttribute(
'href',
'data:application/json;charset=utf-8,' + encodeURIComponent(csvContent)
)
// Set downloaded file name
element.setAttribute('download', csvFileName)
// Hide the elemement and add it to the page
element.style.display = 'none'
document.body.appendChild(element)
// Launch download
element.click()
// Remove element
document.body.removeChild(element)
})
@gk4delltech
Copy link

gk4delltech commented Apr 5, 2024

Does this work for https://teams.microsoft.com/v2/ because I don't get a CSV file.

image

@PodyPoe
Copy link

PodyPoe commented Apr 24, 2024

Does this work for https://teams.microsoft.com/v2/ because I don't get a CSV file.

image

I've been unable to get this to function in "New Teams" myself.

@guillaumemeyer
Copy link
Author

This script is not easily maintainable due to its reliance on unpredictable MS UI updates.
I'm currently investigating a completely different solution to achieve the same result.
Stay tuned

@nabeelq8
Copy link

is there a latest script to download members and owners from teams? can anyone help?

@PodyPoe
Copy link

PodyPoe commented Sep 22, 2024

I've found that if you're on 365, you can get a list now with functions available in https://portal.azure.com/#home, even if you're not an admin.

@fgilic
Copy link

fgilic commented Jun 5, 2025

I've found that if you're on 365, you can get a list now with functions available in https://portal.azure.com/#home, even if you're not an admin.

Thank you @PodyPoe

  1. https://portal.azure.com/
  2. Microsoft Entra ID
  3. Groups -> All groups
  4. Search for a particular group
  5. Members
  6. Bulk operations -> Download members

@H0ntonka
Copy link

H0ntonka commented Dec 1, 2025

The best way to get a Teams email list with bairly any admin rights is to:
Go to the sharepoint site for that Teams and, click on the site content section, (if you don't have it added, just click on edit section from the left and you can find it there), when you go to that section, you just have to click on the name of the Teams group share point at the top, this will pop out a window with an email generated for the list of all members in that Teams channel
Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment