How to fetch all groupmemberships from azure AD powershell irrespective of groupid

Bhanu Prasad 0 Reputation points
2023-02-10T06:22:10.9166667+00:00

How to Fetch the All Group Memberships Irrespective of GroupID

Command or API to get all groupmemberships in AZure AD powershell 5.1

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
{count} votes

3 answers

Sort by: Most helpful
  1. Vasil Michev 119.6K Reputation points MVP Volunteer Moderator
    2023-02-10T07:49:34.45+00:00

    Can you please clarify what exactly you are trying to achieve here? If the idea is to get a list of all Groups and their membership, you can use one of the approaches in this article (either by direct Graph API calls or using the Graph SDK for PowerShell): https://www.michev.info/Blog/Post/4357/report-on-azure-ad-group-members-via-the-graph-api


  2. CarlZhao-MSFT 46,376 Reputation points
    2023-02-10T10:13:10.04+00:00

    Hi @Bhanu Prasad

    Yes, you can use Azure AD PowerShell to get all members of all groups in the tenant, refer to my script:

    Connect-AzureAD
    
    $groups=Get-AzureADGroup -All $true
    ForEach ($group in $groups){
        $members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true  
            Write-output $members
        }
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


  3. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2023-02-10T10:29:27.84+00:00

    Hi @Bhanu Prasad ,

    Thanks for reaching out.

    You can you below script to get the data in csv file.

    $groups=Get-AzureADGroup -All $true
    ForEach ($group in $groups){
        $members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true
        ForEach ($member in $members){
            Write-output $group.DisplayName $member.UserPrincipalName >> C:\Users\Downloads\members1.csv
        }
    }
    

    Hope this will help.

    Thanks,

    Shweta

    Please remember to "Accept Answer" and survey the thread to help others in the community.


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.