Export Microsoft 365 Security Group Members to CSV with PowerShell
Question details
Export the members of a Microsoft 365 security group to a CSV file using PowerShell.

- Product
- Microsoft 365 and Microsoft Graph PowerShell
- Device & OS
- not provided
- Scenario
- A tenant administrator needs a CSV list of a security group's members.
- Observed behavior
- The desired output is a CSV file containing member details for the selected security group.
Have the security group's name or object ID ready, and use an account that can consent to or has been granted the required Microsoft Graph permissions. The older MSOnline module and its Connect-MsolService commands are retired; use Microsoft Graph PowerShell instead.
Export direct group members with Microsoft Graph PowerShell
Use this method to retrieve direct members of a security group and save their available details to CSV.
The export lists direct members, not members of nested groups. Some properties may be blank if they do not apply to a member type or your account lacks permission to read them.
The Microsoft Graph v1.0 group-members endpoint has a known limitation that can omit service principals. Check the Microsoft Graph documentation for alternatives if your group contains service principals.
Open PowerShell and run: Install-Module Microsoft.Graph.Authentication, Microsoft.Graph.Groups -Scope CurrentUser. Approve any installation prompts.
Run Connect-MgGraph -Scopes 'GroupMember.Read.All' and sign in to the correct tenant. Administrator consent or additional permissions may be needed to read details for some member types.
If you do not already have the object ID, run Get-MgGroup -All | Where-Object { $_.SecurityEnabled -eq $true -and $_.DisplayName -eq 'Your group name' } | Select-Object DisplayName, Id. Replace the group name and copy the Id of the intended group.
Replace the group ID and, if needed, the output path in this command: Get-MgGroupMember -GroupId 'group-object-id' -All -Property Id,DisplayName,Mail | Select-Object @{Name='DisplayName';Expression={$_.AdditionalProperties['displayName']}}, @{Name='EmailAddress';Expression={$_.AdditionalProperties['mail']}}, @{Name='MemberType';Expression={$_.OdataType}}, Id | Export-Csv -Path '.\security-group-members.csv' -NoTypeInformation -Encoding UTF8.
Open security-group-members.csv from PowerShell's current directory in a spreadsheet application and review the rows and available fields. Run Get-Location in PowerShell if you need to find that directory.

Review exported group member lists in WPS Spreadsheet
After exporting the CSV with Microsoft Graph PowerShell, use free, lightweight WPS Office to review and organize the list. Its familiar interface and Microsoft Office format compatibility make it easy to move spreadsheet work between applications.

Frequently Asked Questions
Can I still use Connect-MsolService to export group members?
The MSOnline module is retired. Use Connect-MgGraph and Get-MgGroupMember from Microsoft Graph PowerShell instead.
How do I find the security group's object ID?
After connecting with Connect-MgGraph, run Get-MgGroup -All and filter by the group's DisplayName and SecurityEnabled properties. The Id field is the group object ID.
Does the export include members of nested groups?
No. Get-MgGroupMember returns direct members. A nested group can appear as a member, but its own members are not expanded by this command.
Why are some names or email addresses blank?
Some member types do not have a mail address, and Microsoft Graph may return limited details when your account lacks permission to read a member's resource type. Check the member type and your granted permissions.




