azuresearchmicrosoft-graph-api

Azure graph api to search groups whose displayName contains a specific term


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%’ )?

https://graph.microsoft.com/v1.0/groups?$select=id,displayName,description,groupTypes&$orderby=displayName&$top=100&$search=“displayName:123-move”


Solution

  • I tried to reproduce the same in my environment and got the results like below:

    I created Azure AD Groups for testing:

    enter image description here

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

    enter image description here

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

    enter image description here

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

    enter image description here

    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
    

    enter image description here