Forum Discussion

LeeGee76's avatar
LeeGee76
Copper Contributor
Jan 18, 2023

Using Get-AADGroupMember to show Groups only

Hi everyone,

 

I'm looking for some help please...

 

I've been trying to run some powershell script to get a list of members from an Intune Group, however I want to filter on group members only.  I've tried various options, such as the below...

 

Get-AADGroup -groupId xxxx | Get-AADGroupMember | Where-Object {$_.'@odata.type' -contains 'group'} | Get-MSGraphAllPages | Select-Object displayName

 

But I get no results returned.  If I remove 'Where-Object', I successfully receive all members (devices and groups), but really want to show group members only.

 

Could anyone provide any help?

 

Thanks in advance

  • Hi LeeGee76 ,

     

    Use this PowerShell command and it will help you get details of members of the group: (replace the group id)

     

    Get-AzureADGroupMember -ObjectId "1xxxxxx-xxxxxxxxxxxxxxx--dfae68e93ff7"

     

    Best Regards,

    Somesh

    If you find this helpful and it answers your question, please mark it as an “Accepted Solution”.

  • Hi LeeGee76,

     

    Because the Azure AD PowerShell module will be deprecated later this year, I would focus on the Microsoft Graph PowerShell module to be future proof. You can use the following to get the list you want:

    Install-Module Microsoft.Graph.Groups
    Import-Module Microsoft.Graph.Groups
    Connect-MgGraph
    (Get-MgGroupMember -GroupId xxxxxxx | where {$_.AdditionalProperties.'@odata.type' -contains '#microsoft.graph.group'}).AdditionalProperties.displayName
    
    or 
    
    $MemberGroups = Get-MgGroupMember -GroupId xxxxxxx | where {$_.AdditionalProperties.'@odata.type' -contains '#microsoft.graph.group'}
    $MemberGroups.AdditionalProperties.displayName

    The Microsoft Graph PowerShell generates the output a bit different from what you're used to. Most information is within the Additional Properties.

     

    I hope this helps.

     

    Regards,

    Ruud

Resources