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 Security Microsoft Entra Microsoft Entra ID
{count} vote

2 answers

Sort by: Most helpful
  1. soumi-MSFT 11,831 Reputation points Microsoft Employee Moderator
    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 691 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

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.