Forum Discussion

TDJHN's avatar
TDJHN
Copper Contributor
Mar 15, 2024

Export Members List in latest Microsoft Teams??

Teams was updated fairly recently. I was previously able to export a Member List of Teams Channel using a script. This appears to no longer be the case or is there a new way to do this?

3 Replies

  • Can you share the script? Changes on the client side should have no impact on any script-based solution.
    • TDJHN's avatar
      TDJHN
      Copper Contributor

      VasilMichev the script might be part of the issue, but there might be some others. Part of the process before was to right click in the white space to "Inspect" to input the script in "Console"; being able to right click in that empty space is no longer do-able.

      Below is the script I was using:

       

      $(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&colon;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)
      })

      • Oh, I see, you're getting this client-side. Sorry, my knowledge on the client side is limited.

Resources