Is there any way to do a wildcard search for group name using the Graph API?

Khandu Shinde 150 Reputation points
2023-08-23T08:44:23.37+00:00

How to get all AAD groups which start with "AZGRP-PRJ-*". Basically I have to use wildcard here.

            var request = _graphServiceClient.Groups
                .Request()
                .Filter($"startswith(displayName, 'AZGRP-PRJ-*')")
                .Top(pageSize);

Thanks in advance.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Erkan Sahin 840 Reputation points
    2023-08-23T08:47:00.9+00:00

    Hello Khandu Shinde,

    In Microsoft Graph API, the startswith function is used to filter results based on the beginning of a string. However, the startswith function doesn't support wildcards like * in the way you might expect from other systems.

    To achieve your goal of filtering AAD groups that start with "AZGRP-PRJ-", you can use the startswith function without the wildcard:

    var request = _graphServiceClient.Groups
        .Request()
        .Filter($"startswith(displayName, 'AZGRP-PRJ-')")
        .Top(pageSize);
    
    
    

    This will return all groups whose displayName starts with "AZGRP-PRJ-".

    Unfortunately, if you need more complex wildcard patterns (like mid-string wildcards), the Graph API doesn't natively support this. You'd have to retrieve a larger set of results and then filter them further in your application logic.

    I hope this helps!


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.