Null Dynamic Membership Rules in Azure Active Directory

Written by

in

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.

Using null in a Dynamic membership rule

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.

‘Not null’ won’t be accepted as a valid rule when you save

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’

Use $null rather than just 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.

Comments

8 responses to “Null Dynamic Membership Rules in Azure Active Directory”

  1. TLD

    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!

    1. Adam Fowler

      Awesome, glad it helped :)

    2. Adam Fowler

      Awesome, glad to hear it :)

  2. Andreas

    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

    1. Kees

      Thanks, this solved my issue. And Agreed, there should be a ‘nonempty’ operator. ;-)

  3. Sean

    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 :)

  4. Tim Schoeller

    5 years later and they still have not addressed this bug.

Leave a Reply

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

Discover more from AdamFowlerIT.com

Subscribe now to keep reading and get access to the full archive.

Continue reading