Does querying Azure AD (Entra ID) support case insensitive queries?

122 Views Asked by At

I am trying to locate accounts matching a certain phrase in my Azure Active Directory instance. The phrase needs to be case insensitive, however I am not finding a way to do that. All sorts of posts direct me to user 'lower' or 'tolower', which results in the error below.

"Invalid jmespath query supplied for --query: Unknown function: lower()"

Here is what I currently have for a case sensitive search.

az ad user list --query "[?contains(displayName, 'Phrase')]"

This works great if I am trying to match 'Phrase', but fails on 'phrase', 'pHrAse', 'PHRASE', etc.

1

There are 1 best solutions below

0
On

In my tenant, I have 4 Entra ID users named Sridemo in different cases like this:

enter image description here

Note that, Azure CLI does not support case-insensitive filtering directly using JMESPath expressions.

When I tried to retrieve these users by doing case insensitive search using tolower() method, I too got same error:

az ad user list --query "[?contains(tolower(displayName), 'sridemo')]"

Response:

enter image description here

Alternatively, you can make use of below query that initially retrieves all users and filters them by display name converting to lower case:

az ad user list --output json | jq '[.[] | select(.displayName | ascii_downcase | contains("sridemo"))] 

When I ran below script, I got response with expected details along with their count like this:

search_value="SriDemo"
search_lower=$(echo "$search_value" | tr '[:upper:]' '[:lower:]')

az ad user list --output json | jq --arg search "$search_lower" '[.[] | select(.displayName | ascii_downcase | contains($search))] | {count: length, users: .}'

Response:

enter image description here