Aug 23 2021 03:12 PM - edited Aug 23 2021 03:23 PM
In order to download the members of 1000 security groups in AAD and to export members (name, email, upn) for a specific list of security groups with name begins with 'FP3' or from a csv file.
Simply provide the name with which your group starts. e.g. FP3.
The normal limit on returned results is 100 objects, which has been increased to max or "All $True" in this case.
Connect-AzureAD
$PathCsv = "C:\GroupMembers.csv"
$GroupName = Read-Host -Prompt "Enter group name to search"
$groups = Get-AzureADGroup -SearchString $GroupName -all $true
$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 -All $true | Select-Object -Property @{Name = 'GroupName'; Expression= {$GroupName}}, DisplayName, UserPrincipalName
}
$groupMembers | Export-Csv -Path $PathCsv -NoTypeInformation -Force
Original script:
Aug 30 2021 02:41 PM