Azure AD – export groups and members to CSV

UPDATE June ’22 – also check out Active Directory – export groups and members (with email addresses). It’s for on-premises AD but you will easily modify it for Azure AD I’m sure! Wont you? Then why haven’t I yet you say? 🤣😃🤣

UPDATE Sept ’22 – David made me do it – well, he didn’t make me at all really but I did it anyway 🙂. Check out this new post which uses AzAD cmdlets to get the groups and members email, UPN and ObjectID: Azure AD – export groups and members #2.

# export azure ad groups and members to csv (also output empty groups with 'No Members' value) 
# assumes existing connection to Azure AD using Connect-AzureAD (or use a runbook)

$allgroups = Get-AzureADGroup | select ObjectId,DisplayName

$result = foreach ( $group in $allgroups ) {

    $hash = @{GroupName=$group.DisplayName;Member=''}
    $groupid = $group.ObjectId
    if ( $members = Get-AzureADGroupMember -ObjectId $groupid ) {
            foreach ( $member in $members ) {

                $hash.Member = $member.DisplayName
                New-Object psObject -Property $hash
        $displayname = "No Members"
        $hash.Member = $displayname
        New-Object psObject -Property $hash

$result | Export-Csv -Path C:\temp\AzureADGroups.csv -NoTypeInformation

# End

PowerShell get azure ad group members export to csv

export azure ad group members to csv PowerShell

PowerShell export azure ad user group membership to csv