Create and Fill an Entra ID Group based on Local Attributes

Populate Microsoft Entra groups from local device signals using Intune scripts and Azure Automation. Review data collection, identity and membership updates.

Create and Fill an Entra ID Group based on Local Attributes

There is often the need to create an Entra ID group (formerly Azure AD) based on a local registry key or another attribute to make more specific access decisions, to use this group for access rights to an application or many other use cases. Building an AAD group based on local attributes is the perfect way to do exactly that.

In this blog post I will show you how to create an AAD group based on local attributes with the help of Endpoint Analytics and Azure Automation. In my blog I show you how to do this with the example of device manufacturer; of course we already have this info in Intune, but it is just an example of how this works. Of course you can also do this with anything else you can read out on a client.

AAD group based on local attributes

How the AAD group based on local attributes automation works

The value is collected with an Endpoint Analytics Detection script. The collection works by executing a write host.

Create and Fill AAD Group based on an local attributes

If we now look at the result of the remediation script with graph we see that the output of the write-host is also displayed (as far as I know this is only displayable with graph).

Create and Fill AAD Group based on an local attributes

We query this value with an Azure Automation Runbook and check if there is already a group for this manufacturer; if not, the group will be created. After that, all PCs of the manufacturer are added to the group. This is the core logic that lets us build an AAD group based on local attributes fully automatically.

Deploy a Endpoint Analytics Script to collect the value

First we deploy an Endpoint Analytics script to our clients to get the return value with the device manufacturer. This collected value is the foundation for the AAD group based on local attributes that we will build later.

Create and Fill AAD Group based on an local attributes

  • Enter a nameand click Next

Create and Fill AAD Group based on an local attributes

  • Upload the Detectionscript. You can find this small script in my GitHub repository.
  • Click Next > Next

Create and Fill AAD Group based on an local attributes

  • Assign the script to a group
  • Create a schedule. In my case I select daily.
  • Click Next > Create

Create and Fill AAD Group based on an local attributes

Create an App Registration

  • Search for Microsoft Entra ID

Create and Fill AAD Group based on an local attributes

  • Select App registration

Create and Fill AAD Group based on an local attributes

  • Select +New registration

Create and Fill AAD Group based on an local attributes

  • Enter a Name and click Register

Create and Fill AAD Group based on an local attributes

  • Click API permissions and +Add a permission

Create and Fill AAD Group based on an local attributes

  • Select Microsoft Graph

Create and Fill AAD Group based on an local attributes

  • Select Application permissions

Create and Fill AAD Group based on an local attributes

  • Search for DeviceManagementConfiguration.Read.All, Group.Create and GroupMember.ReadWriteAll

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Click Grant admin consent for *** and approve with Yes

Create and Fill AAD Group based on an local attributes

  • Select Certificates & secrets and click +New client secret

Create and Fill AAD Group based on an local attributes

  • Enter a Description and select a Expires time
  • Click Add

Create and Fill AAD Group based on an local attributes

  • Copy and save the Value and the Secret ID

Create and Fill AAD Group based on an local attributes

Create Automation Account

  • Search for Automation Accounts

Create and Fill AAD Group based on an local attributes

  • Click + Create

Create and Fill AAD Group based on an local attributes

  • Select a Subscription and a Resource group
  • Enter an account name and select a Region
  • Click Next

Create and Fill AAD Group based on an local attributes

  • Click Next

Create and Fill AAD Group based on an local attributes

  • Click Next -> Next -> Create

Create and Fill AAD Group based on an local attributes

Create the Runbook

  • Open the Automation Account
  • Navigate to Variables and click + Add a variable

Create and Fill AAD Group based on an local attributes

  • Add the Secret Value, TenantId and the App ID as Variable

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Create and Fill AAD Group based on an local attributes

  • Select Runbooks

  • Click + Create a runbook

Create and Fill AAD Group based on an local attributes

  • Enter a Name
  • Select PowerShell as Runbook type
  • Select 5.1 as Runtime version
  • Click Create

Create and Fill AAD Group based on an local attributes

  • Insert the script from my GitHub repository
  • Change these variables:
    • $scriptName: name of the Endpoint Analytics script
    • $groupPrefix: prefix for the Microsoft Entra ID group

Create and Fill AAD Group based on an local attributes

  • Save and test the script

Create and Fill AAD Group based on an local attributes

Create and Fill AAD Group based on an local attributes

  • Click Publish

Create and Fill AAD Group based on an local attributes

  • Navigate to Schedules and click + Add a schedule

Create and Fill AAD Group based on an local attributes

Create and Fill AAD Group based on an local attributes

  • Click Link to schedule and add the created schedule

Create and Fill AAD Group based on an local attributes

Create and Fill AAD Group based on an local attributes

Conclusion

This script helps to target clients more precisely in the future using local attributes. With an AAD group based on local attributes you can drive dynamic access decisions that would otherwise be impossible. Of course the Manufacturer value is not the best example, as it is already part of the Intune inventory, but it helps to show how the whole mechanism works. If you want to dig deeper into the Graph calls used here, check the official Microsoft Learn documentation, and for more automation ideas have a look at my other Intune automation posts.

Stay healthy, Cheers
Jannik

May Cloudflare measure page views, visits and loading times? The analytics service uses no tracking cookies or session recordings. You can change your choice in the footer at any time.

Privacy details