PowerShell: Get-Team unreliable / returning incomplete results

Copper Contributor



We have multiple issues with the Get-Team cmdlet in the MicrosoftTeams module (v2.3.0). Like many organisations, we're programmatically creating Teams based on organisational data (e.g. one Team to support one Dept/Module/some other business unit).


However, Get-Team often fails to return Teams that we have previously created (and do still exist in Microsoft-land). This makes the data untrustworthy and very difficult to deal with.


This problem can surface in multiple ways:


1) Running "Get-Team" to retrieve all teams


  • Results are often incomplete. When this happens, there are usually around 1-5 'missing' from what we expect, out of around 4000 Teams. 


2) Running "Get-Team -MailNickName" to query for a specific Team. 


  • This will sometimes fail to find a Team. We can run a loop 100 times (with 3 second wait) and it fails to find the Team 100 times. The next day, the Team is found 100 times. Sometimes for example, it's found only 95 times out of 100. 
  • Under the hood, it's using the Graph API. Example of a Team that exists, has an associated UnifiedGroup with ResourceProvisioningOptions=Team):


Get-Team -MailNickName 'thisisateam' -Verbose -Debug

VERBOSE: Done performing authorization
VERBOSE: Executing Get-Team for parameters GroupId: , User: , Archived: , Visibility: , DisplayName: , MailNickName: thisisateam
DEBUG: Making an api call to the uri: https://graph.microsoft.com/beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')&$top=20&$count=true&$search="mailNickname:thisisateam"
DEBUG: Returning 0 teams
VERBOSE: Retrieving groups list
VERBOSE: Done retrieving groups, getting team properties
VERBOSE: Done processing Get-Team



Has anyone else experienced this? 


The other issue is that -MailNickName doesn't return unique results and instead defaults to some kind of wildcard match rather than making a wildcard search optional. This is a problem for efficiently querying for data but can be worked around (by inefficiently passing all results to Where-Object), but I don't want to detract too much from the more urgent problem of unreliable data being returned.


Help much appreciated.


Thank you.



9 Replies

Here is an example script which proves the problem when obtaining all Teams. I've had results between 4454 and 4457, in a tenancy where no Teams are being created or deleted currently.


$LoopCount = 1
$Loops = 10
$WaitTimeSeconds = 400
    if($AllTeams) { $PreviousLoopData = $AllTeams }

    Write-Output "Get-Team Attempt $LoopCount | $(Get-Date -Format 'yyyy-MM-dd-HH-mm-ss')"
        $AllTeams = Get-Team -ErrorAction Stop
        Write-Output "Total Teams Found: $($AllTeams.Count)"

            $Diffs = Compare-Object -ReferenceObject $PreviousLoopData -DifferenceObject $AllTeams -Property MailNickName
            $NewButNotReally = $Diffs | Where-Object { $_.SideIndicator -eq '=>' } | Select-Object -Expand MailNickName
                Write-Output "    - Comparison between previous loop and this loop suggests the following Teams have been CREATED: $($NewButNotReally -join ', ')"
            $DeletedButNotReally = $Diffs | Where-Object { $_.SideIndicator -eq '<=' } | Select-Object -Expand MailNickName
                Write-Output "    - Comparison between previous loop and this loop suggests the following Teams have been DELETED: $($DeletedButNotReally -join ', ')"
    Start-Sleep -Seconds $WaitTimeSeconds
} until ($LoopCount -ge 11)


You'll see things like: "Comparison between previous loop and this loop suggests the following Teams have been DELETED: XXX, YYY"
... and then in the following loop when they reappear again: "Comparison between previous loop and this loop suggests the following Teams have been CREATED: XXX, YYY"
I've just faced a similar issue with the same cmdlet.

1. Here the output seems to be correct
PS H:\> $teams = get-team -user <my UPN here> -Archived $False
PS H:\> $teams.count

2. WTF???
PS H:\> $teams = Get-Team -Archived $false
PS H:\> $teams.count

Regarding the -MailNickName filtering, they have a note at https://docs.microsoft.com/en-us/powershell/module/teams/get-team?view=teams-ps, saying this:

"Get-Team may return multiple results matching the input and not just the exact match for attributes like DisplayName/MailNickName. This is known behavior."

If "known behavior" is a new name for a bug then we may hope it gets fixed eventually.

I must have missed that in the documentation then, thanks!

I believe my issue to be throttling related and the Get-Team cmdlet either by itself or with -MailNickName or -DisplayName won't trigger an exception that shows there is throttling happening.

You can however demonstrate it by overloading the tenancy calling Get-Team multiple times until it starts showing a lower number or 0, and then running Get-Team -GroupId with a valid ID and if you do that *at the right moment* it'll throw an exception with error 429 in the result (which indicates throttling).

I have a script that queries Get-Team for a list of all teams in our tenant (about 150). Randomly certain teams are missing. As a result my script attempts to create the team.

Additionally, and maybe a separate bug. Sometimes when I create a team using my script, the Azure AD group is created but the team is not.


It is truly disconcerting behavior.
I can understand that by default it does an approximate search ("-contains") but a "-exactmatch" parameter would be appreciated so that it returns exactly what I am looking for.
My problem is that I want to retrieve a Team by its "DisplayName" but it returns several Teams.
In the end I workedaround it by filtering the result again by the DisplayName; that is:

$Course = Get-Team -Archived $false -DisplayName $Student.course | Where-Object {$_.DisplayName -eq $Student.course}


We are experiencing the same reliability issues with the Get-Team command.


We script delta files from exports from our LMS and Teams (using Get-Team). But often Get-Team is missing a few (sometimes many) Teams, which leads to already existing Teams being flagged as missing and queued for creation.


It is the only thing that stops us from fully automating Teams/LMS synchronization.


Any news about this? With the latest teams module (4.9.3) there are still issues when quering teams. It seems this has been an issue for quite some time now.


the help states that is only a filter but not an exact match which is unfortunately. It would speed up scripting much more if it would return an exact match.


Curious to know if still more people have issues with teams like that a TeamChannel is created but not the SharePoint folder that should come with it.

The issue still persists but you can fix it with piping the output like below.

get-team -DisplayName $team.Name | Where-Object Displayname -eq $team.name

 I totally agree that it shouldn't work like this, but it's a workaround.