PowerShell script to Export All Azure AD groups Starting with "ABC" name and membership of their groups

Kevin Alive 6 Reputation points
2020-10-26T16:44:44.103+00:00

PowerShell script to Export All Azure AD groups Starting with "ABC" name and membership of their groups

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,437 questions
{count} vote

2 answers

Sort by: Most helpful
  1. soumi-MSFT 11,716 Reputation points Microsoft Employee
    2020-10-27T10:58:03.703+00:00

    Hello @Kevin Alive , thank you for reaching out. Please do check if the following script helps meet your requirements:

    Connect-AzureAD  
    $PathCsv = "C:\temp\GroupMembers.csv"  
    $GroupName = Read-Host -Prompt "Enter group name to search"  
    $groups = Get-AzureADGroup -SearchString $GroupName  
    $groupCount = $groups | measure  
    $count = $groupCount.Count  
      
      
    $groupMembers = foreach($group in $groups){  
        $GroupId = $group.ObjectId  
        $GroupName = $group.DisplayName  
        Write-Progress -Activity "No of Groups found: $count`  
                                  Fetching members for GroupName: $GroupName"  
        Start-Sleep -Milliseconds 200  
        Get-AzureADGroupMember -ObjectId $GroupId | Select-Object -Property @{Name = 'GroupName'; Expression= {$GroupName}}, DisplayName, UserPrincipalName  
    }  
      
    $groupMembers | Export-Csv -Path $PathCsv -NoTypeInformation -Append  
    

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as an Answer; if the above response helped in answering your query.

    2 people found this answer helpful.

  2. Simon Burbery 546 Reputation points
    2022-02-07T21:38:36.33+00:00

    This script will export all groups with members, along with groups that have no members. You can then filter using excel.
    https://www.howdoiuseacomputer.com/index.php/2021/09/12/azure-ad-output-groups-and-members-to-csv/

    0 comments No comments