How to Get AAD Group Members Details Using PowerShell SDK for Microsoft Intune Graph API

We will use PowerShell module for Microsoft Intune Graph API to get Azure AD group members details. If you have not already installed PowerShell SDK for Microsoft Intune Graph API then follow the steps provided in this article to install PowerShell module and connect with MSGraph API with admin consent for first time.

Connect with MSGraph

Type below command on PowerShell and press enter. Provide your Azure AD credential when you get a prompt to connect with MSGraph.

Connect-MSGraph

Get Members Details

We have to use Get-AADGroup & GetAADGroupMember cmdlet to get member details of specific Azure Active Directory group.

List all Azure AD groups

 Get-AADGroup

List specific AD Group

$GroupName = "All Windows 10 and Later Devices"
Get-AADGroup | Where-Object {$_.DisplayName -eq $GroupName}

Get members of specific AD Group

$GroupName = "All Windows 10 and Later Devices"
Get-AADGroup | Where-Object {$_.DisplayName -eq $GroupName} | Get-AADGroupMember

Format the output

$GroupName = "All Windows 10 and Later Devices"
Get-AADGroup | Where-Object {$_.DisplayName -eq $GroupName} | Get-AADGroupMember | Select-Object DisplayName, OperatingSystem, enrollmentType | Format-Table

Export the output

$GroupName = "All Windows 10 and Later Devices"
Get-AADGroup | Where-Object {$_.DisplayName -eq $GroupName} | Get-AADGroupMember | Select-Object * | Export-Csv -Path "C:\temp\Groupmembers.csv"

The Script

Here is final script which you can use to export AAD group membership details in CSV. The script will prompt for AAD group name and export the details of all members in a CSV file. The file will be named as “AAD Group Name-members.csv” and saved in script directory.

$GroupName = Read-Host "Enter AAD Group Name"

$Outfile = "$PSScriptRoot\$GroupName" + "-members.csv"

#Connect with MSGraph if not already connected
Connect-MSGraph

$groupobj = Get-AADGroup | Where-Object {$_.DisplayName -eq $GroupName}
if ($groupobj -eq $null) 
    {write-host "Error: Group '$GroupName' Not Found" -ForegroundColor Red} 
else {
    Get-AADGroup -groupId $groupobj.groupId | Get-AADGroupMember | Export-csv -Path $Outfile
    Write-Host "Details exported in $outfile" -ForegroundColor Green}

Related Posts

Subscribe to Techuisitive Newsletter

Be the first to know about our new blog posts. Get our newsletters directly in your inbox and stay up to date about Modern Desktop Management technologies & news.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top