0

Is there a way from admin center to export all teams owners and members to a CSV file?

I can't run the following code b/c I think it depends on graph api and it might be blocked.

# PowerShell script to export all Microsoft Teams Owners and Members to a CSV file
$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 "`nProcessed Teams count: $Count" "`nCurrently 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 "`nProcessed Teams count: $Count" "`nCurrently Processing: $TeamName" -Completed

if ((Test-Path -Path $Path) -eq "True") {
    Write-Host "`nReport available in $Path" -ForegroundColor Green
}
1

1 Answer 1

0

Try installing the Microsoft Teams PowerShell module to run the PowerShell script you provided in your post.

Documentation: Microsoft Teams PowerShell Overview

You can also use PnP PowerShell or CLI for Microsoft 365 for exporting owners and members or Microsoft teams.

PnP PowerShell:

$AdminCenterURL="https://contoso-admin.sharepoint.com/"

# Connect to SharePoint Online admin center

Connect-PnPOnline -Url $AdminCenterURL -Interactive

$dateTime = (Get-Date).toString("dd-MM-yyyy")
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$fileName = "m365GroupUsersReport-" + $dateTime + ".csv"
$OutPutView = $directorypath + "\Logs\"+ $fileName

# Array to Hold Result - PSObjects
$m365GroupCollection = @()

# Retrieve all M365 groups associated with Microsoft teams
$m365Groups = Get-PnPMicrosoft365Group | where-object {$_.HasTeam -eq $true}

$m365Groups | ForEach-Object {
    $ExportVw = New-Object PSObject
    $ExportVw | Add-Member -MemberType NoteProperty -name "Group Name" -value $_.DisplayName
    $m365GroupOwnersName="";
    $m365GroupMembersName="";
    
    # For auditing purpose
    $m365GroupOwnersName = (Get-PnPMicrosoft365GroupOwner -Identity $_.GroupId | select -ExpandProperty DisplayName) -join ";";
    $m365GroupMembersName = (Get-PnPMicrosoft365GroupMember -Identity $_.GroupId | select -ExpandProperty DisplayName) -join ";";

    $ExportVw | Add-Member -MemberType NoteProperty -name "Group Owners" -value $m365GroupOwnersName
    $ExportVw | Add-Member -MemberType NoteProperty -name "Group Members" -value $m365GroupMembersName
    $m365GroupCollection += $ExportVw
}

# Export the result array to CSV file
$m365GroupCollection | sort "Group Name" |Export-CSV $OutPutView -Force -NoTypeInformation

# Disconnect SharePoint online connection

Disconnect-PnPOnline

CLI for Microsoft 365:

$dateTime = (Get-Date).toString("dd-MM-yyyy")
$directorypath = "D:\dtemp"
$fileName = "MSTeamsUsersReport-" + $dateTime + ".csv"
$OutPutView = $directorypath + "\"+ $fileName

# Array to hold results - PSObjects
$msTeamsUsersCollection = @()

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
    m365 login
}

# Retrieve all teams in Microsoft Teams
$msTeams = m365 teams team list | ConvertFrom-Json

$msTeams | ForEach-Object {
    $ExportVw = New-Object PSObject
    $ExportVw | Add-Member -MemberType NoteProperty -name "Team Name" -value $_.displayName
    $teamOwnerNames = "";
    $teamMemberNames = "";
    $teamGuestNames = "";
    
    $teamOwnerNames = (m365 teams user list --teamId $_.id --role Owner | ConvertFrom-Json | select -ExpandProperty displayName) -join ";"
    $teamMemberNames = (m365 teams user list --teamId $_.id --role Member | ConvertFrom-Json | select -ExpandProperty displayName) -join ";"
    $teamGuestNames = (m365 teams user list --teamId $_.id --role Guest | ConvertFrom-Json | select -ExpandProperty displayName) -join ";"
    
    $ExportVw | Add-Member -MemberType NoteProperty -name "Team Owners" -value $teamOwnerNames
    $ExportVw | Add-Member -MemberType NoteProperty -name "Team Members" -value $teamMemberNames
    $ExportVw | Add-Member -MemberType NoteProperty -name "Team Guests" -value $teamGuestNames
    $msTeamsUsersCollection += $ExportVw
}

# Export the results to CSV file
$msTeamsUsersCollection | sort "Team Name" |Export-CSV $OutPutView -Force -NoTypeInformation

# Disconnect M365 connection
m365 logout

Source: List all Microsoft Teams team's Owners and Members

3
  • why am I getting localhost :0501 error after i put in admin credentials. and I didn't get authencator code
    – maria
    Commented Mar 12 at 16:58
  • Which PowerShell code are you exactly now, MS Teams PS or PnP PowerShell or CLI for M365? You mean you have MFA enabled for your account? Commented Mar 13 at 4:41
  • Still doesn't work in the GCC tenant. Are there different ways to do this in GCC
    – maria
    Commented Apr 8 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.