Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
ccopca
Regular Visitor

Power BI - Can't get Azure AD Members (from a group)

Hello All,

I need to get all member (and all fields from that table) from two groups from Azure AD. I have tried different ways, so far no luck.

I used OData Feed and Graph as below, and both lines just retrieve the id (member Id)

https://graph.microsoft.com/v1.0/groups/{my group Id}/members?$count=true

or

https://graph.microsoft.com/v1.0/groups/{my group Id}/members?$select=id,deviceId,displayName

I'm new in power bi and I will need to do more reports getting data from Intune and Azure AD. 

What it would be the right way to get these data?

Thanks

cc

3 REPLIES 3

Cool!  How do I use Powershell as a source in Power Query though?

ccopca
Regular Visitor

Thank s for your response Jianbo Li. This is going to be my first Power BI report and I'm kind of lost.

The reports will show certain devices data from Intune that are assigned to two groups (Azure AD groups I supposed, because I can't find any group in Intune). From Power BI, I can get the devices data from Intune Data Warehouse.

Can  you explain me how to use the Get-AzureADGroupMember cmdlet in PowerShell to retrieve the data from Power BI.

 

Many thanks,

cc 

v-jianboli-msft
Community Support
Community Support

Hi @ccopca ,

 

you can use the Get-AzureADGroupMember cmdlet in PowerShell to get all members and all fields from a group in Azure AD . You can specify the -ObjectId parameter with the ID of the group you want to query, and use the -All parameter to return all group members and fields. For example:

Get-AzureADGroupMember -ObjectId "group1-id" -All $true
Get-AzureADGroupMember -ObjectId "group2-id" -All $true

If you want to get all members and fields of nested groups, you can use a custom function in PowerShell that recursively queries the subgroups and returns all users and fields. For example:

Function Get-AzureADGroupMembers($groupId) {
  $output = @()
  $group = (Get-AzureADGroupMember -ObjectId $groupId -All $True| Select ObjectId).ObjectId
  foreach($objectid in $group) {
    $aad_object = Get-AzureADObjectByObjectId -ObjectId $objectid
    #Add to output if object is a user or a device
    if ($aad_object.ObjectType -eq 'User' -or $aad_object.ObjectType -eq 'Device') {
      $output += New-Object PSObject -Property @{ 
        Name = $aad_object.DisplayName
        UserPrincipalName = $aad_object.UserPrincipalName
        ObjectId = $aad_object.ObjectId
        ObjectType = $aad_object.ObjectType
      }
    }
    #Recursively call function if object is a group
    if ($aad_object.ObjectType -eq 'Group') {
      $output += Get-AzureADGroupMembers -groupId $objectid
    }
  }
  return $output
}

#Call function for each group you want to query
Get-AzureADGroupMembers -groupId "group1-id"
Get-AzureADGroupMembers -groupId "group2-id"

Refer to:

azure - Powershell : Get-AzureADGroupMember get all memebers of nested groups - Stack Overflow

Get-AzureADGroupMember (AzureAD) | Microsoft Learn 

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.