compare a set of azure ad groups and find members who are in more then one of this set

Alexander 266 Reputation points
2021-04-14T16:42:23.25+00:00

Hello, my brain is a bit lost i would like to do following (MS Graph or Powershell all would be fine)?!

I need to compare a set of azure ad groups and find members who are in more then one of this set and list them.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,518 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,384 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 95,411 Reputation points MVP
    2021-04-14T19:54:48.267+00:00

    Hi @Alexander ,

    maybe this is helpful to get started:

    ## AzureAD PowerShell module required  
      
    # Get AAD Groups and Group Memberships  
    $users1 = Get-AzureADgroup -Searchstring "Test1" | Get-AzureADGroupMember  
    $users2 = Get-AzureADgroup -Searchstring  "Test2" | Get-AzureADGroupMember  
    $users3 = Get-AzureADgroup -Searchstring  "Test3" | Get-AzureADGroupMember  
    # Compare Group1 and Group2  
    $compareObj1 = Compare-Object -ReferenceObject $users1 -DifferenceObject $users2 -ExcludeDifferent -IncludeEqual  
    $inGrp1andGrp2 = $compareObj1.InputObject.DisplayName  
    # Compare Group1 and Group3  
    $compareObj2 = Compare-Object -ReferenceObject $users1 -DifferenceObject $users3 -ExcludeDifferent -IncludeEqual  
    $inGrp1andGrp3 = $compareObj2.InputObject.DisplayName  
    # Compare Group2 and Group3  
    $compareObj3 = Compare-Object -ReferenceObject $users2 -DifferenceObject $users3 -ExcludeDifferent -IncludeEqual  
    $inGrp2andGrp3 = $compareObj3.InputObject.DisplayName  
    # Results  
    $inGrp1andGrp2  
    $inGrp1andGrp3  
    $inGrp2andGrp3  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Chris Hill 191 Reputation points
    2021-11-03T12:45:19.72+00:00

    For larger groups you want to change your calls to 'Get-AzureADGroupMember' to 'Get-AzureADGroupMember -all $true'

    0 comments No comments