Forum Discussion
Export members for a list of security groups from AAD
This is the same script that you highlighted and has been adjusted a little bit.
When prompted, 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-https://bit.ly/3kzxQvh -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:
https://docs.microsoft.com/en-us/answers/questions/139633/powershell-script-to-export-all-azure-ad-groups-st-1.html
- aliat_IMANAMIAug 30, 2021Brass ContributorHere is an updated https://www.imanami.com/powershell-and-active-directory/?utm_source=mstechcommunity&utm_medium=qa&utm_campaign=qa_powershell-and-active-directory, It will now only look for the Groups starting with input value.In this case just key in FP3 and it will only bring groups that begin with FP3.Connect-AzureAD
$PathCsv = "C:\temp\GroupMembers.csv"
$GroupName = Read-Host -Prompt "Enter group Displayname to search"
$groups = Get-AzureADGroup -All $true | Where-object {$_.DisplayName -like "$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 -All $true | Select-Object -Property @{Name = 'GroupName'; Expression= {$GroupName}}, DisplayName, UserPrincipalName
}
$groupMembers | Export-Csv -Path $PathCsv -NoTypeInformation