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.
#Parameters $clientId = "1950a258-227b-4e31-a9cf-717495945fc2" $redirectUri = "urn:ietf:wg:oauth:2.0:oob" $resourceURI = "https://graph.microsoft.com" $authority = "https://login.microsoftonline.com/common" #Remove commenting on username and password if you want to run this without a prompt. #$Office365Username='[email protected]' #$Office365Password='VeryStrongPassword' #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); } else { # 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 = 'https://graph.microsoft.com/beta/Groups/' $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 = "https://graph.microsoft.com/beta/Groups/$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" } }
Line 43 has you statement in it which throws an error in powershell. Otherwise this worked great!
LikeLiked by 1 person
Thanks for the heads up. Just a “bug” from the wordpress HTML editor after i did a change to the post.
LikeLike
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:
$teamName=$NameType.DisplayName
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!
LikeLike
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
LikeLike
[…] API can now get a list of all of your Microsoft Teams. That is pretty cool. Check out this post for all the […]
LikeLike
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?
LikeLike
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
LikeLike
What are the steps to get the Microsoft.IdentityModel.Clients.ActiveDirectory.dll properly installed?
LikeLike
You can install the azurerm.profile module instead by typing install-module azurerm.profile
LikeLike
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 https://docs.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-beta
LikeLike
Glad that you found it helpfull. Here is a more in dept on explaining opwershell/graph api:
https://alexholmeset.blog/2018/10/10/getting-started-with-graph-api-and-powershell/
Graph API for Teams is out of beta now.
Here how to work with tabs in Graph:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/teamstab_add
Under the same category(Apps), you see how to list alll apps availible and what ID they have so you can use for adding a tab.
Hope this helps. DM me on Twitter if you have any more questions.
LikeLike
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?
LikeLike
The client ID i used is a general powershell ID. Take a look here for a better way to create client ID:
https://alexholmeset.blog/2019/03/05/trigger-azure-automation-with-teams-team-request-form/
The logon/token part is better here also as you dont need to enter user/password in a logon window, you only use a application secret
LikeLike
Thanks Alexander!
LikeLike
One thing to remember is that if you have over 100 teams, a new request is needed to get the next 100 teams. Think there will be a URL in the first request reply for the next 100.
LikeLike