How to Create Azure AD Dynamic Groups for Managing Devices using Intune

How to Create Azure AD Dynamic Groups for Managing Devices using Intune? This post will see how to create Dynamic device groups and User Groups in Azure Active Directory. Azure AD groups are similar to collections (in the SCCM world) for Intune device management solutions.

These AAD groups can be used to target different policies to a specific group of devices. Latest postValidate Azure AD Dynamic Group Rules | Intune.

So this is very important in the world of modern management of devices using Microsoft Intune. If you are an SCCM admin, the AAD dynamic group is similar to creating a dynamic collection using WQL query rules. AAD groups don’t have that granularity in creating dynamic query rules if you compare them with WQL query rules.

However, the new Azure portal has many options to create dynamic query rules. The video tutorial will help you get more inside of AAD Dynamic groups.

Patch My PC

Updated Post -> How To Create Nested Azure AD Dynamic Groups.

Create Azure AD Dynamic Groups

AAD Dynamic membership advanced rules are based on binary expressions. One Azure AD dynamic query can have more than one binary expression. Each binary expression in the AAD dynamic membership rule query must have 3 parts Left parameter, the Binary operator, and the Right constant.

A left parameter in the query rule is one of the attributes of the AAD object (either user or device). If you want to query users in a particular department, then the user is the object, and the department is the attribute (user.department).

A binary operator is nothing other than a conditional operator like “-ne,-eq, -contains -match.” The right constant is a constant value specific to your requirement; for example, if you want to create a group for all IT users, it is “IT.”

(user.department -startsWith "IT")
(user.department -match "IT")
(user.department -eq "IT")

Maximum supported words/characters

I did a test to understand what is the maximum supported words/characters in Azure AD dynamic advanced membership rule, and I found that we could save a query with a maximum of 311 words and 3045 characters.

When I increased the numbers to 315 words and 3085 characters, it started giving an error “Failed to create Group_Maxi. Undefined,” where MAXI is the group name.

How to Create Azure AD Dynamic Groups for Managing Devices using Intune
How to Create Azure AD Dynamic Groups for Managing Devices using Intune

Now back to Intune and device management. I will create 3 basic groups for device management. These AAD dynamic device groups (All Windows Devices, All iOS Devices, and All Android Devices) will be used to deploy different configuration policies.

Dynamic Query

First, I wanted to group all windows devices in my Intune environment. There are two ways to create an AAD group with dynamic membership query rules 1. Simple rule and 2. Advanced Rule. To group windows devices based on the operating system, it’s better to use simple queries via Azure portal GUI.

In case you want to use advance membership, then the following is the query “(device.deviceOSType -contains “Windows”).” When you create an Azure AD dynamic device group, it will take 1 or 2 minutes (depending upon the complexity of the query and the size of the database) to populate the devices into the group.

How to Create Azure AD Dynamic Groups for Managing Devices using Intune
How to Create Azure AD Dynamic Groups for Managing Devices using Intune

It’s time to find iOS devices (iPhone or iPad) in my environment via AAD Dynamic query and group them into an AAD dynamic group. Unlike the Windows device group, the iOS device AAD dynamic Device group can’t be created using a simple membership rule; rather, we should use the Advanced membership rule.

We need to have two constant values like iPhone and iPad. Following is the query which I used to fetch iOS devices (device.deviceOSType -contains “iPhone”) -or (device.deviceOSType -contains “iPad”).

How to Create Azure AD Dynamic Groups for Managing Devices using Intune
How to Create Azure AD Dynamic Groups for Managing Devices using Intune

OK, here we go with a grouping of Android devices. I want to create an AAD dynamic device group using a simple membership rule in this scenario.

Because I don’t have more than one constant value in the AAD group binary expression. Following is the dynamic query for the Android device group “(device.deviceOSType -contains “Android”).”

How to Create Azure AD Dynamic Groups for Managing Devices using Intune
How to Create Azure AD Dynamic Groups for Managing Devices using Intune

Author

Anoop is Microsoft MVP! He is a Solution Architect in enterprise client management with more than 20 years of experience (calculation done in 2021) in IT. He is a blogger, Speaker, and Local User Group HTMD Community leader. His main focus is on Device Management technologies like SCCM 2012, Current Branch, and Intune. E writes about ConfigMgr, Windows 11, Windows 10, Azure AD, Microsoft Intune, Windows 365, AVD, etc…

15 thoughts on “How to Create Azure AD Dynamic Groups for Managing Devices using Intune”

  1. Anoop -this post is really helpful, thanks very much for taking the time to write it up.

    I wondered however if you could let me know how you found that you should use ‘deviceOSType’ – when I created dynamic groups for users it it is easy to get a list of attributes…not sure how to do the same for devices.

    Many thanks!

    Carl

    Reply
  2. Awesome thanks – I managed to create a dynamic group that contained devices whilst waiting for your update, from this group I could get an object in this group and | fl to get full details. I will read your post now also as Graph is another area of interest to me.

    Thanks again

    Reply
  3. Hi Anoop,
    Any way we can create AAD Device groups based on AD OU, Programs Installed, basically like more granular queries like we can with SCCM collections?

    Thanks

    Reply
  4. Is there any option to create a user Group based on the Device Type they are using? For e.g. create a user group for all MacOS users.

    Reply
    • I think you are trying to replicate the sccm collection logic to azure ad dynamic groups. If so, I don’t think that is possible …. you might need to use requirements rules or custom script for that … I suppose

      Reply
  5. Would you know of a way to create a dynamic device group based on the primary user for the device? I’m trying to create one that includes devices with a specific group tag and primary users whose userprincipalname doesn’t include a certain string.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.