Forum Discussion

TonyRedmond's avatar
Dec 20, 2018

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

  • ashokjingar's avatar
    ashokjingar
    Copper Contributor

    TonyRedmond 

     

    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

    • praestegaard's avatar
      praestegaard
      Copper 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

    • adam deltinger's avatar
      adam deltinger
      MVP
      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

Resources