Export Azure users from specific group and include their membership

Trivego 1 Reputation point
2021-03-19T15:48:33.787+00:00

Hi!

Does anybody know a good script to export users from an specific/primary group, which will also search and export the users secondary/other groups, which was included in the primary group?

Does anybody also know how to filter to only look for an specific group from the secondary group?

I have found this: https://learn.microsoft.com/en-us/answers/questions/139633/powershell-script-to-export-all-azure-ad-groups-st-1.html#

1, Export the users from X Azure group.
2, Make it look at the users own membership.
3, Filter the users own membership groups so it only looks at Y Azure groups.
4, Export the results ,including the Users primary group aswell as secondary groups.

Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 37,206 Reputation points Microsoft Employee Moderator
    2021-03-29T21:47:51.8+00:00

    I do not believe that there is an official guide for this, but there are a number of blog posts and forum threads from people who have found ways to accomplish this.

    One of the best ones I've seen so far is this post by Bas Wijdenes that allows you to export both groups and nested groups via Powershell.

    $Grp = Get-AzureADGroup -Filter "DisplayName eq '$Group'" -ErrorAction Stop
    Members = Get-AzureADGroupMember -ObjectId $Grp.ObjectId -ErrorAction Stop
    
    Get-AzureADNestedGroupMembers -Groups 'GROUPNAME' -ObjectType Users
    

    The full script is listed here on Github.

    This other example uses "Get-AzureADGroupMember" and exports the users to a CSV.

    Get-AzureADGroupMember -ObjectId 84b18857-3c01-48be-b707-492019c57142 | select UserPrincipalName,ProxyAddresses | Export-Csv -nti example.csv

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.