Automate hybrid Active Directory with a PowerShell runbook
Drive on-prem AD groups from attributes in a hybrid environment. Here is how it works with Entra ID dynamic groups, a PowerShell runbook on a hybrid worker, and Entra Connect under one rule model.
In a hybrid environment your users live in two places at once: in Microsoft Entra ID and in your on-prem Active Directory. You manage access in both. In the cloud you can use dynamic groups, but on-prem AD has no such mechanism. This article shows how to automate group memberships in on-prem AD based on attributes anyway, with a PowerShell runbook on a hybrid worker and Entra Connect syncing the changes back. One rule model drives both directories.
TL;DR
- On-prem Active Directory has no dynamic groups, so attribute-based membership has to be driven by something you run yourself.
- A PowerShell runbook on a hybrid worker reads attributes from AD and applies the group memberships in AD.
- Entra Connect syncs those AD changes back to Entra ID, so the cloud follows along.
- In the cloud you set up the same logic with Entra ID dynamic groups. One rule model for both directories.
- ServiceChanger reacts by default to the attributes already in your directory. Always test a new rule on a small test group first.
Why on-prem AD differs from the cloud
Entra ID has dynamic groups: you write a membership rule and Entra fills the group itself. On-prem Active Directory does not. AD groups are static. If you want an AD group to follow from an attribute like department or job title, there has to be a process that reads the attributes and updates the memberships.
That is exactly the gap a runbook fills. The runbook is a PowerShell script that runs on a schedule or a trigger, reads the relevant attributes, and puts the right users in the right AD groups. And what should be removed, it removes again.
The role of the hybrid worker and Entra Connect
A runbook in an Azure automation account runs in the Azure cloud by default and cannot reach your domain controllers from there. For on-prem work you use a hybrid worker: a machine in your own network that runs the runbook locally, with line of sight to AD. The runbook uses the Active Directory PowerShell module to change groups and memberships.
Entra Connect does the other half. As soon as the runbook changes a membership in AD, Entra Connect picks that change up on the next sync and pushes it to Entra ID. So your cloud side needs to know nothing special: it simply sees the synchronized group.
The flow in order:
- An attribute in AD changes (for example a user's department).
- The runbook runs on the hybrid worker, reads the attribute, and determines the right set of groups.
- The runbook updates the AD group memberships: it adds what belongs, removes what no longer fits.
- Entra Connect syncs the changed groups to Entra ID.
- The cloud side follows along without a separate action.
The model: one attribute, a set of groups
The core of the model is simple. One attribute value stands for a whole set of groups. You set the attribute, the set follows. Change the attribute, the set swaps and the stale memberships are cleaned up. No separate tickets per group, no forgotten leftover access.
In pseudocode the rule looks like this: