Null Dynamic Membership Rules in Azure Active Directory

Azure Active Directory has the ability to create Security Groups with Dynamic membership. This is great if you can apply logic to a group, as members will fall in and out of scope without any work required.

Microsoft have a great writeup on how it all works and how to create rules, however I’ve run into a scenario not covered in the documentation.

If you create a Dynamic membership rule and want to include only attributes that have no value, the term ‘null’ works fine. You can create your group or modify the rule without issue.
However, if your binary operator (the equals part in the example above) is set to ‘not’, it won’t work.
The use case I had for ‘not null’ was to have a group of users which only had employee numbers, which was an easy way of filtering out test accounts, service accounts and so on.

You’ll get this error:

Failed to create group

Failed to create group ‘groupname’. Dynamic membership rule validation error: Invalid operands found for operator.Invalid operands found for operator -not

The way to fix this is to go into the ‘Advanced Rule’ option and change the term ‘null’ to ‘$null’

Note that you can’t do this from the simple rule view, changing ‘null’ to ‘$null’ there results in the code looking like this:

(user.extensionAttribute1 -eq “$null”)

Where it should look like this, without the quotes:

(user.extensionAttribute1 -eq $null)

A simple fix, but something that’s not documented on the support page. Hope this helps anyone who runs into the same problem.

8 thoughts on “Null Dynamic Membership Rules in Azure Active Directory

  1. Thank you! This resolved my issue. I was trying to do something similar… only grabbing accounts where the JobTitle was not blank. I had been using (user.jobTitle -ne “”). It was accepted but ignored. (user.jobTitle -ne $null) did the trick!

  2. Thank you very much! This is exactly what I needed. I don’t understand why there is not “notempty” operator or why they didn’t document this.
    For me, it didn’t work with -not $null but it worked with -ne $null

  3. Hey people, I just tried the above example and it didn’t like it. Perhaps MS has changed the rules.

    This is the example MS provided to base a query on NOT NULL.
    -not (user.extensionAttribute1 -eq null)

    My Example was to get “All Contractors” that “Have a TelephoneNumber”:
    (user.extensionAttribute4 -eq “Contractor”) -and -not (user.TelephoneNumber -eq null)

    Worked a treat :)

    Thanks for sharing this content :)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.