Find all Teams teams using Graph API and PowerShell!


Now you can use the Graph API to get a list of all the teams in Microsoft Teams.
Before you had to rely on the exchange module to get a good answer, but that did not last long as Microsoft started to prepare all Office 365 Groups for Teams.

I have written av short script that looks trough all groups and checks if there is a team provisioned to it.

$clientId = "1950a258-227b-4e31-a9cf-717495945fc2"
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceURI = ""
$authority = ""
#Remove commenting on username and password if you want to run this without a prompt.
#$Office365Username='[email protected]'
#pre requisites
try {
$AadModule = Import-Module -Name AzureAD -ErrorAction Stop -PassThru
catch {
throw 'Prerequisites not installed (AzureAD PowerShell module not installed)'
$adal = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority

##option without user interaction
if (([string]::IsNullOrEmpty($Office365Username) -eq $false) -and ([string]::IsNullOrEmpty($Office365Password) -eq $false))
$SecurePassword = ConvertTo-SecureString -AsPlainText $Office365Password -Force
#Build Azure AD credentials object
$AADCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserPasswordCredential" -ArgumentList $Office365Username,$SecurePassword
# Get token without login prompts.
$authResult = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions]::AcquireTokenAsync($authContext, $resourceURI, $clientid, $AADCredential);
# Get token by prompting login window.
$platformParameters = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList "Always"
$authResult = $authContext.AcquireTokenAsync($resourceURI, $ClientID, $RedirectUri, $platformParameters)
$accessToken = $authResult.result.AccessToken

$apiUrl = ''
$myProfile = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl -Method Get
$GroupsList = $myprofile | select-object Value
$Groups = $GroupsList.Value | Select-Object Id

foreach($Group in $Groups){
   $GroupId = $Group.Id
   $apiUrl2 = "$Groupid/"
   $GroupsData = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $apiUrl2 -Method Get
   $NameType = $GroupsData | Select-Object resourceProvisioningOptions,DisplayName
   If($nametype.resourceProvisioningOptions -eq 'Team'){
       $NameType.DisplayName+" is Teams enabled"
   else {
       $NameType.DisplayName+" is not Teams enabled"

15 thoughts on “Find all Teams teams using Graph API and PowerShell!

  1. Another one I noticed, when running against a large org its too easy to miss a group that is enabled because everything is followed up with “is not teams enabled” or “is teams enabled”. I added:

    Write-Host $teamName “is Teams enabled” -foregroundcolor green

    and made it red for the “is not teams enabled” groups. It makes it a little easier to pick out of a list. Cheers!


    • Good 🙂 i did the script verry basic just for people to get started with the data. Could for example put each team into a variable and output to csv for example


  2. I ran this and it only found a small handful of the Teams we have. I got an error up front about the fact that it couldn’t set the Path variable because a dll doesn’t exist. Maybe I need to install something as a pre-req?


    • You can use the azurerm.profile module instead. Install-module azurerm.profile,
      The import-module Azurerm.profile. Then you can comment out the c:\ path line


  3. Thanks a lot, this was really helped me understand Graph REST API with powershell.. but still I have some queries.
    The point is, I have a task for creating Teams using a CSv, I am able to create teams with Channel List, but further I also need to create configurable tabs in those channels.
    Is there any MS Graph REST API available for Creating TABs (within PowerShell -***)
    Link For MS Graph API


  4. Hi, the script worked very well first time – thank you. I tweaked it a little to output as a CSV. The one thing I don’t understand and the client ID bit – is that the client id for your environment?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s