PowerShell Get-Team token error

Chris Mancey (Group) 221 Reputation points
2021-11-08T16:33:17.697+00:00

I've been trying to use the following powershell command to get all the tenant teams

Get-Team -Archived $false | Export-csv c:\output.csv

But because of the number of teams we have in our tenant 40k+ it times out with the following error

Get-Team : Error occurred while executing
Code: InvalidAuthenticationToken
Message: Access token has expired or is not yet valid.

Is there a way to refresh the token so this doesn't happen or get a sub-set of the teams i.e all those starting with a or the first 10K, second 10K

Thanks

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
617 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,144 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,383 questions
{count} votes

Accepted answer
  1. Martin Rublik 316 Reputation points
    2021-11-10T13:31:05.203+00:00

    Did you consider using -NumberOfThreads parameter? This could speed-up the process.

    Martin


1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,386 Reputation points
    2021-11-11T09:19:31.667+00:00

    Hi there,

    To list all teams in an organization (tenant), you find all groups that have teams, and then get information for each team.
    To get a list of all groups in the organization that have teams, get a list of all groups and then in code find the ones that have a resourceProvisioningOptions property that contains "Team". Since groups are large objects, use $select to only get the properties of the group you care about.

    You can follow this link for the detailed process
    List all teams in Microsoft Teams for an organization
    https://learn.microsoft.com/en-us/graph/teams-list-all-teams

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--