Forked from guillaumemeyer/export-team-membership-roster.js
Last active
August 24, 2023 10:57
-
-
Save LaurinchenMe/9216a06a7c4d0ca8dbd3156de10684d3 to your computer and use it in GitHub Desktop.
Exports the owners and members of a Microsoft Teams team as a CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **************************************************************************************************************************** | |
// Abstract: | |
// This script is just a quick hack to export the UPN of the owners and members of a team as a CSV file without administrator permissions. | |
// This is a workaround for the problem that all information about the owners and members are displayed in one column. | |
// | |
// Usage: | |
// 1. Open MS Teams in Browser | |
// 2. Open your team | |
// 3. Select "Manage team" from its menu | |
// 4. Select the "Members" tab | |
// 5. Expand the "Owners" and "Members and guests" sections | |
// 6. 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) | |
// 7. Open your browser console (press F12) | |
// 8. Copy and paste all the content of this script to the console and press "Enter" | |
// 9. 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 = '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 upn = $('.td-member-photo img').eq(index).attr('upn') | |
// Append to the CSV content | |
const csvRow = 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) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment