PowerShell script to Export All Azure AD groups Starting with "ABC" name and membership of their groups
PowerShell script to Export All Azure AD groups Starting with "ABC" name and membership of their groups
Hi, have you looked at this document? It shows how you can export using PowerShell custom commands.
Hello @KevinAlive-6994, thank you for reaching out. Please do check if the following script helps meet your requirements:
Connect-AzureAD
$PathCsv = "C:\temp\GroupMembers.csv"
$GroupName = Read-Host -Prompt "Enter group name to search"
$groups = Get-AzureADGroup -SearchString $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 | Select-Object -Property @{Name = 'GroupName'; Expression= {$GroupName}}, DisplayName, UserPrincipalName
}
$groupMembers | Export-Csv -Path $PathCsv -NoTypeInformation -Append
Hope this helps.
Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as an Answer; if the above response helped in answering your query.
I would suggest adding an "-All" in line 4 so you know for sure you get all the results returned.
Why have the Start-Sleep at line 14?
I would also suggest adding another proptery in the form of the GroupId because as far as I remembered the groupname doesn't have to be unique technically.
I know this is a bit old, but I just wanted to say I came across it and it worked perfectly for me with the same ask, so thanks a bunch!
This script will export all groups with members, along with groups that have no members. You can then filter using excel.
https://www.howdoiuseacomputer.com/index.php/2021/09/12/azure-ad-output-groups-and-members-to-csv/
4 people are following this question.