Forum Discussion
RobinMalik
Jul 19, 2021Copper Contributor
PowerShell: Get-Team unreliable / returning incomplete results
Hi, 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 T...
RobinMalik
Jul 19, 2021Copper Contributor
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
do
{
if($AllTeams) { $PreviousLoopData = $AllTeams }
Write-Output "Get-Team Attempt $LoopCount | $(Get-Date -Format 'yyyy-MM-dd-HH-mm-ss')"
try
{
$AllTeams = Get-Team -ErrorAction Stop
Write-Output "Total Teams Found: $($AllTeams.Count)"
if($PreviousLoopData)
{
$Diffs = Compare-Object -ReferenceObject $PreviousLoopData -DifferenceObject $AllTeams -Property MailNickName
$NewButNotReally = $Diffs | Where-Object { $_.SideIndicator -eq '=>' } | Select-Object -Expand MailNickName
if($NewButNotReally)
{
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
if($DeletedButNotReally)
{
Write-Output " - Comparison between previous loop and this loop suggests the following Teams have been DELETED: $($DeletedButNotReally -join ', ')"
}
}
}
catch
{
$_
}
Start-Sleep -Seconds $WaitTimeSeconds
$LoopCount++
} 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"
... 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"
- DeletedJul 28, 2021I'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
18
2. WTF???
PS H:\> $teams = Get-Team -Archived $false
PS H:\> $teams.count
4- DeletedJul 28, 2021Regarding 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.- RobinMalikAug 05, 2021Copper Contributor@Vadim
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).