Aug 20 2021
02:40 PM
- last edited on
Jan 14 2022
03:25 PM
by
TechCommunityAP
Aug 20 2021
02:40 PM
- last edited on
Jan 14 2022
03:25 PM
by
TechCommunityAP
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 using the PS command from this post but the script seems incorrect as line 3 is asking to key just one security group. Tried using wildcard, FP3* but doesn't seem to work too. Thanks in advanced.
Aug 21 2021 03:33 AM
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. :)
Aug 21 2021 03:36 AM
Aug 21 2021 03:39 AM
Aug 23 2021 01:58 PM
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-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 26 2021 01:55 PM
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
Aug 26 2021 02:02 PM
Aug 30 2021 02:39 PM