question

Alex-5595 avatar image
0 Votes"
Alex-5595 asked ChrisAtMAF answered

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

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.

azure-ad-user-managementmicrosoft-graph-groupsazure-ad-group-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered AndreasBaumgarten commented

Hi @Alex-5595 ,

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ok Compare-Object i thought about, but the output options for me are not a charm. Thank you very much though.

0 Votes 0 ·

What kind of output options do you have in mind?


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

Regards
Andreas Baumgarten

0 Votes 0 ·
ChrisAtMAF avatar image
0 Votes"
ChrisAtMAF answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.