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.

# Add ADAL (Microsoft.IdentityModel.Clients.ActiveDirectory.dll) assembly path from Azure Resource Manager SDK location
Add-Type -Path "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Profile\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
# or simply import AzureRm module using below command
Import-Module AzureRm.profile
#PowerShell Client Id. This is a well known Azure AD client id of the PowerShell client. No need of registering a Azure AD app.
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2"
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceURI = ""
$authority = ""
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority

    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.UserCredential" -ArgumentList $Office365Username,$SecurePassword
    # Get token without login prompts.
    $authResult = $authContext.AcquireToken($resourceURI, $clientId,$AADCredential)
    # Get token by prompting login window.
    $authResult = $authContext.AcquireToken($resourceURI, $clientId, $redirectUri, [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always)
    $accessToken = $authResult.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"

5 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


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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s