Share via

PowerShell Get-Team token error

Chris Mancey (Group) 226 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

Windows for business | Windows Server | User experience | PowerShell
Microsoft Teams | Microsoft Teams for business | Other
Microsoft Security | Microsoft Identity Manager

Answer accepted by question author

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

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Limitless Technology 40,106 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--

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.