Häufig besteht der Bedarf, eine Microsoft Entra ID-Gruppe (ehemals Azure AD) auf Basis eines lokalen Registry-Keys oder eines anderen Attributs zu erstellen, um spezifischere Zugriffsentscheidungen treffen zu können, diese Gruppe für Zugriffsrechte auf eine Anwendung zu nutzen oder für viele weitere Anwendungsfälle. In diesem Blogbeitrag zeige ich dir, wie du das mithilfe von Endpoint Analytics und Azure Automation umsetzt. In meinem Blog zeige ich dir das am Beispiel des Geräteherstellers; natürlich haben wir diese Information bereits in Intune, aber es ist nur ein Beispiel dafür, wie das Ganze funktioniert. Selbstverständlich kannst du das auch mit allem anderen machen, was du auf einem Client auslesen kannst.

Inhaltsverzeichnis
Wie funktioniert das
Der Wert wird mit einem Endpoint Analytics-Detection-Skript erfasst. Die Erfassung erfolgt durch die Ausführung eines Write-Host.

Wenn wir uns jetzt das Ergebnis des Remediation-Skripts mit Graph ansehen, sehen wir, dass auch die Ausgabe des Write-Host angezeigt wird (soweit ich weiß, ist das nur mit Graph darstellbar).

Diesen Wert fragen wir mit einem Azure Automation Runbook ab und prüfen, ob bereits eine Gruppe für diesen Hersteller existiert; falls nicht, wird die Gruppe erstellt. Danach werden alle PCs des Herstellers der Gruppe hinzugefügt.
Wichtig dabei ist, dass das Runbook idempotent arbeitet: Es legt eine Gruppe nur dann an, wenn sie noch nicht existiert, und ergänzt bei jedem Lauf lediglich die fehlenden Geräte. Dadurch kannst du den Zeitplan bedenkenlos täglich ausführen, ohne doppelte Gruppen oder doppelte Mitgliedschaften zu riskieren. Ein praktischer Tipp aus der Praxis: Plane das Runbook zeitlich nach dem Endpoint-Analytics-Skript ein, damit beim Lauf bereits aktuelle Werte vorliegen. Andernfalls greift die Automatisierung beim ersten Durchlauf auf veraltete oder noch leere Werte zu, und neue Geräte landen erst einen Zyklus später in der passenden Gruppe.
Ein Endpoint Analytics-Skript zum Erfassen des Werts bereitstellen
Zuerst stellen wir ein Endpoint Analytics-Skript auf unseren Clients bereit, um den Rückgabewert mit dem Gerätehersteller zu erhalten.
- Öffne Endpoint Analytics
- Klicke auf + Create script package

- Gib einen Namen ein und klicke auf Next

- Lade das Detection -Skript hoch. Dieses kleine Skript findest du in meinem GitHub-Repository.
- Klicke auf Next > Next

- Weise das Skript einer Gruppe zu
- Erstelle einen Zeitplan. In meinem Fall wähle ich daily.
- Klicke auf Next > Create

Eine App Registration erstellen
- Suche nach Microsoft Entra ID

- Wähle App registration

- Wähle +New registration

- Gib einen Namen ein und klicke auf Register

- Klicke auf API permissions und +Add a permission

- Wähle Microsoft Graph

- Wähle Application permissions

- Suche nach DeviceManagementConfiguration.Read.All, Group.Create und GroupMember.ReadWriteAll
- Klicke auf Grant admin consent for *** und bestätige mit Yes

- Wähle Certificates & secrets und klicke auf +New client secret

- Gib eine Description ein und wähle eine Expires time
- Klicke auf Add

- Kopiere und speichere den Value und die Secret ID

Automation Account erstellen
- Suche nach Automation Accounts

- Klicke auf + Create

- Wähle eine Subscription und eine Resource group
- Gib einen Account-Namen ein und wähle eine Region
- Klicke auf Next

- Klicke auf Next

- Klicke auf Next -> Next -> Create

Das Runbook erstellen
- Öffne das Automation Account
- Navigiere zu Variables und klicke auf + Add a variable

- Füge den Secret Value, die TenantId und die App ID als Variable hinzu
- Wähle Runbooks
- Klicke auf + Create a runbook

- Gib einen Namen ein
- Wähle PowerShell als Runbook type
- Wähle 5.1 als Runtime version
- Klicke auf Create

- Füge das Skript aus meinem GitHub-Repository ein
- Ändere diese Variablen:
- $scriptName: Name des Endpoint Analytics-Skripts
- $groupPrefix: Präfix für die Microsoft Entra ID-Gruppe

- Speichere und teste das Skript


- Klicke auf Publish

- Navigiere zu Schedules und klicke auf + Add a schedule


- Klicke auf Link to schedule und füge den erstellten Zeitplan hinzu


Fazit
Dieses Skript hilft dabei, Clients in Zukunft anhand lokaler Attribute präziser zu adressieren. Natürlich ist der Wert Manufacturer nicht das beste Beispiel, da er bereits Teil des Intune-Inventars ist, aber er hilft zu zeigen, wie der gesamte Mechanismus funktioniert.
Bleib gesund, Cheers
Jannik









Where does it store the data?
Im curious why it wouldn’t be easier to store advanced inventory for your machines in Log Analytics and using something like the following to populate a table.
https://msendpointmgr.com/2021/04/12/enhance-intune-inventory-data-with-proactive-remediations-and-log-analytics/
This is also an nice way to collect inventory but this has an big disadvantage. You have to add the log analytic key in the script. When you run endpoint analytics script you can see the code in the log file. With this key you have the possibility to flood the Loganalytics workspace.
[…] https://jannikreinhard.com/2022/08/28/create-and-fill-aad-group-based-on-an-local-attributes/ […]
Nice idea 🙂
With large device numbers you could speed things up a bit by using a PATCH request to add up to 20 members to a group at once, and fallback to an individual POST if needed.
[…] output is an JSON string. You can use this solution described in the “Create and Fill AAD Group based on an local attributes” blog post how you can fill a AAD group based on this result. If you need support by adapting […]
[…] To see which devices are using a particular monitor or keyboard, it can be very helpful if you can collect this information. In this blog I will show you how to do this with the help of Endpoint Analytics. You can then use this information to assign a driver to these devices or to trigger a hardware replacement. How you can automatically populate a group based on the output of an endpoint analytics script I explained in this blog post. […]
Great workaround. This is a feature that would be beneficial to have built in to Intune.
Additionally it would be nice to have a way to move a device from one existing AAD group to another existing AAD group based on local attributes. Example if device have currently settings X in use and then these got switched to something else that you want to track. In this type of case device should not be part of two or more specific AAD groups at the same time.
Is this something you have test? Do you have a script for it?
Hey Jouni, this should not be an big deal only a small adaption of the automation scrip. If you need support let me know. I am happy to help you
[…] Create and Fill AAD Group based on an local attributes […]