Step 1

Create the dynamic groups

Create two dynamic security groups. Their rules decide membership, so nobody adds people by hand.

10 minutesNeeds Groups Administrator or Global Administrator

Name them properly

Use one pattern for every group in the tenant: <Type>-CON-<Purpose>-<Target>[-DYN].

PartValues
TypeSG security group · M365 Microsoft 365 group or Team · DL distribution list
PurposeLIC licensing · CA Conditional Access · INT Intune · ROLE admin roles · APP app access
-DYNMembers come from a rule

Create the groups

PowerShell
Connect-MgGraph -TenantId contoso.onmicrosoft.com -Scopes "Group.ReadWrite.All","Directory.ReadWrite.All" -NoWelcome

$students = New-MgGroup -DisplayName "SG-CON-LIC-A5-Students-DYN" -MailNickname "sg-con-lic-a5-students-dyn" `
  -MailEnabled:$false -SecurityEnabled -GroupTypes "DynamicMembership" -MembershipRuleProcessingState "On" `
  -Description "Contoso | Licensing | A5 Student | synced users whose UPN starts stu" `
  -MembershipRule '(user.dirSyncEnabled -eq true) -and (user.userPrincipalName -startsWith "stu")'

$staff = New-MgGroup -DisplayName "SG-CON-LIC-A5-Staff-DYN" -MailNickname "sg-con-lic-a5-staff-dyn" `
  -MailEnabled:$false -SecurityEnabled -GroupTypes "DynamicMembership" -MembershipRuleProcessingState "On" `
  -Description "Contoso | Licensing | A5 Faculty | synced users whose UPN does not start stu" `
  -MembershipRule '(user.dirSyncEnabled -eq true) -and (user.userPrincipalName -notStartsWith "stu")'

$students, $staff | Select-Object DisplayName, Id
Different naming at your school?

The rules match the pupil naming from the Active Directory guides, where pupil accounts use their admission number with a stu prefix. If your pupils follow another pattern, match on that instead, or on the department attribute.

Your progress is kept in this browser only.