In a related post I explained how to get the e-mail addresses for a specific Microsoft Teams GroupId: https://deafops.net/how-to-get-the-e-mail-addresses-for-a-microsoft-teams-group/

But what if you want to get additional properties from the Azure Active Directory (AAD)?

It is Powershell to the rescue again. With Powershell, we can just get the team and iterate over each team member, retrieving what we need from the Azure AD.

We need both the Teams Powershell module and the Azure AD Powershell module.
Teams: Microsoft Docs on installing MS Teams Powershell.
Azure AD: Microsoft Docs on installing Azure AD Powershell.

With the Powershell Teams module installed, you can now connect to your Teams environment:

Connect-MicrosoftTeams

And connect to the Azure Active Directory:

Connect-AzureAD

Now that we succesfully completed both login challenges, we can proceed with querying both the Team and the Azure AD:

Get-TeamUser -GroupId 1234f56c-1234-4c02-ba92-ced12e3c1d45 | ForEach-Object {Get-AzureADUser -ObjectId $_.UserId | Select-Object -Property UserPrincipalName, jobTitle, department } | Export-Csv -Path 'C:\Export\Export.csv'

In this case we are retrieving the UserPrincipalName, jobTitle and department for each user in the Microsoft Teams team with GroupId ‘1234f56c-1234-4c02-ba92-ced12e3c1d45’.

The full list of default supported properties retrievable through the Microsoft Graph using the Get-AzureADUser commandlet are listed here.

Depending on your configuration and setup not all values are always maintained by your system administrator.

When you want to retrieve all information for a user, run this Powershell command:

Get-TeamUser -GroupId 1234f56c-1234-4c02-ba92-ced12e3c1d45 | ForEach-Object {Get-AzureADUser -ObjectId $_.UserId | Select * }

In case you are wondering where to get the GroupId for your Team, you can just right-click on your Team and copy it over from the ‘Get link to team’-feature.