Jul 19 2021 02:47 AM - edited Jul 19 2021 02:50 AM
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 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
2) Running "Get-Team -MailNickName" to query for a specific 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.
Jul 19 2021 04:34 AM
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)
Jul 28 2021 12:13 AM
Jul 28 2021 12:18 AM
Jul 28 2021 12:18 AM
Aug 05 2021 08:22 AM
Feb 08 2022 07:13 AM
Feb 16 2022 02:23 AM
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}
Mar 29 2022 12:34 PM
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.
Feb 09 2023 09:28 AM
@UlrikSS
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.
Aug 02 2023 05:50 AM
@Erwin_de_Jong
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.