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...
Schnittlauch
Aug 21, 2021Iron Contributor
Hi filzah
I can offer you this script:
$Groups = Get-AzureADGroup -SearchString FP3
foreach ($group in $groups) {
Get-AzureADGroupMember -ObjectId $group.ObjectId | fl DisplayName,UserPrincipalName
}
You can simply change the Searchstring. I used your "FP3"
Don't forget to export it into your format (CSV or whatever)
Please give me a little feedback, if I met your requirements :'D
Best regards,
Schnittlauch
"First, No system is safe. Second, Aim for the impossible. Third, no Backup, no Mercy" - Schnittlauch
My answer helped you? Don't forget to leave a like. Also mark the answer as solved when your problem is solved. 🙂
filzah
Aug 26, 2021Copper Contributor
Hi Schnittlauch Thanks so much for replying. Almost there! I used the code below but somehow the results are incomplete. Would you know why and how I can rectify this?
Connect-AzureAD
$groups=Get-AzureADGroup -SearchString FP3_Share_IS_
$resultsarray =@()
ForEach ($group in $groups){
$members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true
ForEach ($member in $members){
$UserObject = new-object PSObject
$UserObject | add-member -membertype NoteProperty -name "Group Name" -Value $group.DisplayName
$UserObject | add-member -membertype NoteProperty -name "Member Name" -Value $member.DisplayName
$UserObject | add-member -membertype NoteProperty -name "ObjType" -Value $member.ObjectType
$UserObject | add-member -membertype NoteProperty -name "UserType" -Value $member.UserType
$UserObject | add-member -membertype NoteProperty -name "UserPrinicpalName" -Value $member.UserPrincipalName
$resultsarray += $UserObject
}
}
$resultsarray | Export-Csv -Encoding UTF8 -Delimiter ";" -Path "C:\scripts\output.csv" -NoTypeInformation