How to Create a Dynamic Group in M365 Excluding Certain Users?

September 23, 2025 3 answers
Asked by TechieExplorer24
I'm trying to set up a new Dynamic Group in Microsoft 365 that includes all of my users with Microsoft Defender licenses but excludes users in the 'Business Premium Users' group and the 'External Staff' group. I have 10 Microsoft Business Premium licenses for some users and 100 Microsoft Defender licenses for others. I've already created the necessary groups, but I'm running into issues with the syntax for the exclusion in my Dynamic Group rules. I really want to automate the assignment of Microsoft Defender licenses since staff turnover can be quite regular. Any guidance or tips would be amazing!

Answers

ConfusedCoder
I should have shared my example in my original post! Right now, my Dynamic Rule Expression looks something like this: -not (user.objectId -in ["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]) for the Business Premium group, but it seems like those users are still popping up in the group. Any ideas why?
Reply to this answer
SyntaxSavvy101
Make sure to include the syntax youโ€™re currently using for the Dynamic Group. A common mistake is trying to use group names instead of their Object IDs when referencing `memberOf`. That might be throwing things off for you! Youโ€™ll need to stick with the ObjectID.

LogicNinja89: Good catch! It definitely needs the group's ObjectID, not the name.

TechieExplorer24: Correct, I'm already using the ObjectID... just added a reply with more details!

Reply to this answer
AdminGuru92
Instead of excluding groups directly, consider using a rule based on the licensed property along with a property to identify external staff. The `memberOf` attribute canโ€™t be used with other operators, so just check the licensing properties instead. It might simplify things for you.

TechieExplorer24: I did see a post about that, but I couldn't figure out the specific details needed...

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions