Forum Discussion
Using PowerShell to Check Group or Team Membership
PowerShell is great at getting lots done for Office 365 administrators. As an example, here are a couple of ways to check the membership of an Office 365 Group or a Microsoft Team to find out whether a specific user is already present. You might never need to use this tip, but then again, it's always surprising when PowerShell comes to the rescue.
https://www.petri.com/powershell-check-group-team-membership
9 Replies
- ashokjingarCopper Contributor
Hi Tony,
I've seen a few of your wonderful scripts to do with Groups and Teams hence I feel you are the best person to ask this. Is it possible via PowerShell to get a list of Teams and what Groups they have residing in them.
I know that within Microsoft Teams, you can add members to a Team, which can be individuals and Groups. It is those groups that were added that I need to see. Is this possible?
Thank you in advance,
Ash
- praestegaardCopper Contributor
ashokjingar I just stumpled upon this thread and registered myself to tell you that theres a module that lets you fetch Office 365 groups that are used for abstracting a membership of af Teams team.
'MicrosoftTeams' | ForEach-Object -Process { if (-not (Get-Module -name $_ -ListAvailable)) { Install-Module -Name $_ -Scope CurrentUser } Import-Module -Name $_ -ErrorAction Stop } $connection = Get-Variable -Name connection -ValueOnly -ErrorAction SilentlyContinue if (-not $connection) { Write-Host -Object "There might be a MS login pop-up window that you havent noticed" -BackgroundColor Yellow -ForegroundColor Black $connection = Connect-MicrosoftTeams -ErrorAction Stop } #endregion Init Write-Host -Object 'Fetching all Teams groups' $team = Get-Team Write-Host -Object 'Fetching all Teams groupmembers' $teamUser = $team | Get-TeamUser
-Anders
- I doubt this because you actually aren’t adding any groups to teams!
you’re just doing a one time import of the member of those groups. So you’ll probably just see the members being added- ashokjingarCopper Contributor
Thanks for your reply. If you read the following article, TonyRedmond makes a comment that in Azure AD, background synchronisation takes place eventually. Meaning that if you add a new user to a particular Group in Azure AD, that new user should eventually appear in the Team that uses that Group. So that would imply that Teams/Azure AD knows which Groups belong to which Team.
Regards,
Ash
- bbhorriganBrass Contributor
This is really useful, thanks Tony you are the best!