I’m using the following Azure graph api to search groups whose displayName contains a specific term (i.e. 123-move), but the response includes names like “1234-move” as well. Does anyone know how to do a SQL-Like query (I.e. select * from groups where displayName like ‘%123-move%’
)?
I tried to reproduce the same in my environment and got the results like below:
I created Azure AD Groups for testing:
When I tried to use Search query, I got the 1234-move also in the response like below:
https://graph.microsoft.com/v1.0/groups?$select=id,displayName,description&$search="displayName:123-move")
So, to search groups whose displayName contains a specific term you have to make use of contains query. But when I tried to use contains, I got the error like below:
https://graph.microsoft.com/v1.0/groups?$select=id,displayName,description,groupTypes&$filter=contains(displayName,'123-move')
Note that: Contains is not supported in Azure Graph API. Make use of either search or filter parameters only.
So, you can make use of startswith
parameter to fetch the groups which starts 123-move
like below:
https://graph.microsoft.com/v1.0/groups?$select=id,displayName&$filter=startswith(displayName,'123-move')
As a workaround, you can make use of PowerShell to fetch the groups which starts 123-move
like below:
Connect-AzureAD
$groups = Get-AzureADGroup -All $true | Where-Object { $_.DisplayName -like '*123-move*' }
$groups