Exporting Entra ID Group Members (All) with PowerShell

Exporting Entra ID Group Members (All) with PowerShell:

Recently, while working with Intune deployments, I was asked to extract devices from a specific group into a CSV format. This task seemed straightforward, but problem arose when attempting to gather all members, including those within nested groups.

While the Intune or Entra ID portal offers a convenient option to export members using direct members, bulk operations, and a simple click on "Download members," it falls short when it comes to exporting devices associated with nested groups. This limitation spurred the exploration of alternative methods, leading to the discovery of PowerShell as a powerful solution.

The following screenshot shows how you can download the direct members using the Entra ID or intune console.

image

If you want to download all members using the console, there is no download members available.

image

Exporting Members with PowerShell

Unlike the portal's constraints, PowerShell enables us to extract comprehensive device details not available through direct member downloads. Leveraging the Microsoft Graph command Get-MgGroup, part of the "Microsoft.Graph.Groups" module, we gain access to an array of device information crucial for deployment scenarios.

Before diving into the script execution, ensure that the executing account have the necessary graph permissions, primarily read access. Without adequate permissions, Graph may restrict access, hindering the script's functionality.

For more information about the Powershell command and module, please refer https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/get-mggroup?view=graph-powershell-1.0

image

image

Script Overview

The script's functionality extends beyond the portal's limitations, empowering users to export both direct and nested group members effortlessly. Here's a concise breakdown of its operation:

  1. Module Validation: The script verifies the presence of the Entra ID groups module and installs it if absent, ensuring seamless execution.
  2. Graph API Connection: Establishing a connection to the Microsoft Graph API with requisite permissions is vital for accessing Entra ID group data.
  3. User Input: User is prompted to input the Entra ID group name, facilitating targeted member extraction.
  4. Data Extraction: Upon validation, the script retrieves the group's ID and exports member details to a CSV file. This file encompasses crucial device information such as name, operating system, creation date, registration date, last sign-in date, and device ID.

The script is uploaded to Github repository for download.

Screenshots of the script execution and output data.

image

Output:

image

image

Conclusion

In summary, PowerShell serves as a robust tool for circumventing portal limitations and extracting comprehensive device data for deployment purposes. By leveraging the Get-MgGroup command, users can streamline Intune deployments and fulfill requests for exporting all devices associated with Entra ID groups.

Leave a Reply