Forum Discussion
filzah
Aug 20, 2021Copper Contributor
Export members for a list of security groups from AAD
Hi. I need to download the members of 1000 security groups in AAD. Can I export members (name, email, upn) for a specific list of security groups with name begins with 'FP3' or from a csv file? Tried...
filzah
Aug 26, 2021Copper Contributor
Hi. I keyed FP3 but results were inaccurate as it is showing other groups that doesn't begin with FP3 too.
aliat_IMANAMI
Aug 30, 2021Brass Contributor
Here 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
$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