Microsoft Teams PowerShell Commands to List All Members and Owners

For this post I wanted to go over some of the basic commands to manage Microsoft Teams and how to simply pull off a report showing all Teams members and Owners within PowerShell.

First open PowerShell and install the Teams module:

Install-Module -Name MicrosoftTeams -RequiredVersion 0.9.6

 

Then connect to your Teams tenant using this command:

Connect-MicrosoftTeams -TenantId 28b1254c-145f-1248-84cd-3148154d8a15

 

You can get your tenant ID by logging in to Microsoft Azure AD, going to properties and copying the Directory ID box

Microsoft Teams PowerShell Commands to List All Members and Owners




Then straight away you should be able to see which commands are available by running:

get-command -module MicrosoftTeams

 

The built-in commands are as follows:

Add-TeamUser
Connect-MicrosoftTeams
Disconnect-MicrosoftTeams
Get-Team
Get-TeamChannel
Get-TeamFunSettings
Get-TeamGuestSettings
Get-TeamHelp
Get-TeamMemberSettings
Get-TeamMessagingSettings
Get-TeamUser
New-Team
New-TeamChannel
Remove-Team
Remove-TeamChannel
Remove-TeamUser
Set-Team
Set-TeamChannel
Set-TeamFunSettings
Set-TeamGuestSettings
Set-TeamMemberSettings
Set-TeamMessagingSettings
Set-TeamPicture

You can then try a few commands as below:

get-team | export-csv c:\temp\teams.csv

Get-TeamMemberSettings

Get-TeamUser -GroupId cbcshd8a-f376-44e4-8233-4f91012547fd

Get-Team -User test.user@domain.com | select displayname

 

To list all Microsoft Teams members and owners we can use a script:

Connect-MicrosoftTeams -AccountId user@domain.onmicrosoft.com

$AllTeams = (Get-Team).GroupID
$TeamList = @()

Foreach ($Team in $AllTeams)
{       
        $TeamGUID = $Team.ToString()
        $TeamName = (Get-Team | ?{$_.GroupID -eq $Team}).DisplayName
        $TeamOwner = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Owner'}).Name
        $TeamMember = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Member'}).Name

        $TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMembers = $TeamMember -join ', '}
}

$TeamList | export-csv c:\temp\TeamsData.csv -NoTypeInformation 

 




This script will just give you a list of all users that are a member of a Team within your tenant:

Connect-MicrosoftTeams

$Teams = Get-Team

$FolderPath = 'c:\temp\uniqueusers.csv'

$users = @()

ForEach( $i in $Teams.GroupId){

$users += Get-TeamUser -GroupId $i

}

$uniqUsers = $users | sort UserId -Unique

$uniqUsers | Export-Csv -Path $FolderPath 

8 Replies to “Microsoft Teams PowerShell Commands to List All Members and Owners”

  1. Thanks for sharing. However, when I get the cmdlet list it doesn’t include everything you show in your list. I don’t see:
    Get-TeamFunSettings
    Get-TeamGuestSettings
    Get-TeamMemberSettings
    Get-TeamMessagingSettings

    Do you happen to know why?

  2. Update: I found the answer to my question regarding the cmdlets I don’t see. Microsoft consolidated these cmdlets into the Get-Team cmdlet in April 2020.

  3. Couple of little tweaks to “To list all Microsoft Teams members and owners we can use a script” which dramatically speeds up the script as it reduces the number of commands executed.

    $AllTeams = Get-Team
    $TeamList = @()

    foreach ($Team in $AllTeams)
    {
    $TeamGUID = $Team.GroupId.ToString()
    $TeamName = $Team.DisplayName
    write-host $TeamName
    $TeamUsers = Get-TeamUser -GroupId $TeamGUID
    $TeamOwner = ($TeamUsers | Where-Object {$_.Role -eq ‘Owner’}).User
    $TeamMember = ($TeamUsers | Where-Object {$_.Role -eq ‘member’}).User
    $TeamList = $TeamList + [PSCustomObject]@{
    TeamName = $TeamName;
    TeamObjectID = $TeamGUID;
    TeamOwners = $TeamOwner -join ‘; ‘;
    TeamMembers = $TeamMember -join “;”;
    }
    }
    $TeamList | export-csv c:\temp\TeamsData.csv -NoTypeInformation

  4. This is my take on this, it produces a list of all teams members and their role in each team.

    function GetTeamsMembers ($Groupid) {

    if ($null -eq $groupid) {
    $Teams = Get-Team
    }
    else {
    $teams = Get-Team -GroupId $groupid
    }

    Foreach ($Team in $Teams) {
    $TeamGUID = $Team.GroupID.ToString()
    $TeamName = $team.DisplayName
    #$TeamOwner = (Get-TeamUser -GroupId $Team | ? { $_.Role -eq ‘Owner’ }).Name
    #$TeamMember = (Get-TeamUser -GroupId $Team | ? { $_.Role -eq ‘Member’ }).Name

    foreach ($User in (Get-TeamUser -GroupId $TeamGUID ) ) {
    [PSCustomObject]@{
    TeamName = $TeamName
    TeamObjectID = $TeamGUID
    Identity = $User.User
    UserName = $user.name
    UserID = $user.UserId
    Role = $user.role
    }
    }
    }
    }

    GetTeamsMembers | Export-Csv c:\temp\teamsusers_2020-10-27.csv -NoTypeInformation -Encoding UTF8 -Delimiter “;”

  5. I can get list of members, owners for Team(s) and list in .csv file. However, the list includes employees not visible in Teams because they are no longer with the company.

    Is there a way to filter list and only get those members who are current employees, or active in Active Directory?

    Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *