List groups
Article
05/13/2022
18 minutes to read
15 contributors
In this article
Namespace: microsoft.graph
List all the groups available in an organization, excluding dynamic distribution groups. To retrieve dynamic distribution groups, use the Exchange admin center .
This operation returns by default only a subset of the properties for each group. These default properties are noted in the Properties section. To get properties that are not returned by default, do a GET operation for the group and specify the properties in a $select
OData query option. The hasMembersWithLicenseErrors property is an exception and is not returned in the $select
query.
Note: This request might have replication delays for groups that were recently created, updated, or deleted.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
GroupMember.Read.All, Group.Read.All, Directory.Read.All, Group.ReadWrite.All, Directory.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
GroupMember.Read.All, Group.Read.All, Directory.Read.All, Group.ReadWrite.All, Directory.ReadWrite.All
HTTP request
GET /groups
Optional query parameters
This method supports the $count
, $expand
, $filter
, $orderBy
, $search
, $select
, and $top
OData query parameters to help customize the response. The default and maximum page sizes are 100 and 999 group objects respectively. Some queries are supported only when you use the ConsistencyLevel header set to eventual
and $count
. For more information, see Advanced query capabilities on Azure AD directory objects .
To list only Microsoft 365 groups (aka unified groups), apply a filter on groupTypes :
GET https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified')
The $search
query parameter supports tokenization only on the displayName and description fields and requires the ConsistencyLevel header. Fields other than displayName and description default to $filter
startswith
behavior.
For more information on OData query options, see OData query parameters . For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Name
Description
Authorization
Bearer {token}. Required.
ConsistencyLevel
eventual. This header and $count
are required when using $search
, or in specific usage of $filter
. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Request body
Do not supply a request body for this method.
Response
If successful, this method returns a 200 OK
response code and collection of group objects in the response body. The response includes only the default properties of each group.
Examples
Example 1: Get a list of groups
Request
The following is an example of the request.
GET https://graph.microsoft.com/v1.0/groups
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var groups = await graphClient.Groups
.Request()
.GetAsync();
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var groups = await graphClient.Groups
.Request()
.GetAsync();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.get();
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
GroupCollectionPage groups = graphClient.groups()
.buildRequest()
.get();
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
GroupCollectionPage groups = graphClient.groups()
.buildRequest()
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.Groups().Get()
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.Groups().Get()
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability. All the default properties are returned for each group in an actual call.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
"value": [
{
"id": "45b7d2e7-b882-4a80-ba97-10b7a63b8fa4",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-12-22T02:21:05Z",
"description": "Self help community for golf",
"displayName": "Golf Assist",
"expirationDateTime": null,
"groupTypes": [
"Unified"
],
"isAssignableToRole": null,
"mail": "golfassist@contoso.com",
"mailEnabled": true,
"mailNickname": "golfassist",
"membershipRule": null,
"membershipRuleProcessingState": null,
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": "CAN",
"preferredLanguage": null,
"proxyAddresses": [
"smtp:golfassist@contoso.onmicrosoft.com",
"SMTP:golfassist@contoso.com"
],
"renewedDateTime": "2018-12-22T02:21:05Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [],
"securityEnabled": false,
"theme": null,
"visibility": "Public",
"onPremisesProvisioningErrors": []
},
{
"id": "d7797254-3084-44d0-99c9-a3b5ab149538",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-11-19T20:29:40Z",
"description": "Talk about golf",
"displayName": "Golf Discussion",
"expirationDateTime": null,
"groupTypes": [],
"isAssignableToRole": null,
"mail": "golftalk@contoso.com",
"mailEnabled": true,
"mailNickname": "golftalk",
"membershipRule": null,
"membershipRuleProcessingState": null,
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": "CAN",
"preferredLanguage": null,
"proxyAddresses": [
"smtp:golftalk@contoso.onmicrosoft.com",
"SMTP:golftalk@contoso.com"
],
"renewedDateTime": "2018-11-19T20:29:40Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [],
"securityEnabled": false,
"theme": null,
"visibility": null,
"onPremisesProvisioningErrors": []
}
]
}
Example 2: Get a filtered list of groups including the count of returned objects
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual
because $count
is in the request. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Note: The $count
and $search
query parameters are currently not available in Azure AD B2C tenants.
Request
GET https://graph.microsoft.com/v1.0/groups?$count=true&$filter=hasMembersWithLicenseErrors+eq+true&$select=id,displayName
ConsistencyLevel: eventual
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var groups = await graphClient.Groups
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("hasMembersWithLicenseErrors eq true")
.Select("id,displayName")
.GetAsync();
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var groups = await graphClient.Groups
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("hasMembersWithLicenseErrors eq true")
.Select("id,displayName")
.GetAsync();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.header('ConsistencyLevel','eventual')
.filter('hasMembersWithLicenseErrors eq true')
.select('id,displayName')
.get();
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.header('ConsistencyLevel','eventual')
.filter('hasMembersWithLicenseErrors eq true')
.select('id,displayName')
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$count=true&$filter=hasMembersWithLicenseErrors%20eq%20true&$select=id,displayName"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$count=true&$filter=hasMembersWithLicenseErrors%20eq%20true&$select=id,displayName"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
GroupCollectionPage groups = graphClient.groups()
.buildRequest( requestOptions )
.filter("hasMembersWithLicenseErrors eq true")
.select("id,displayName")
.get();
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
GroupCollectionPage groups = graphClient.groups()
.buildRequest( requestOptions )
.filter("hasMembersWithLicenseErrors eq true")
.select("id,displayName")
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Count: true,
Filter: "hasMembersWithLicenseErrors%20eq%20true",
Select: "id,displayName",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Count: true,
Filter: "hasMembersWithLicenseErrors%20eq%20true",
Select: "id,displayName",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Import-Module Microsoft.Graph.Groups
Get-MgGroup -CountVariable CountVar -Filter "hasMembersWithLicenseErrors eq true" -Property "id,displayName" -ConsistencyLevel eventual
Import-Module Microsoft.Graph.Groups
Get-MgGroup -CountVariable CountVar -Filter "hasMembersWithLicenseErrors eq true" -Property "id,displayName" -ConsistencyLevel eventual
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of the response which includes only the requested properties.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups(id,displayName)",
"@odata.count":2,
"value":[
{
"id":"11111111-2222-3333-4444-555555555555",
"displayName":"Contoso Group 1"
},
{
"id":"22222222-3333-4444-5555-666666666666",
"displayName":"Contoso Group 2"
}
]
}
Example 3: Get only a count of groups
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual
because $count
is in the request. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Note: The $count
and $search
query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups/$count
ConsistencyLevel: eventual
Response
The following is an example of the response.
HTTP/1.1 200 OK
Content-type: text/plain
893
Example 4: Use $filter and $top to get one group with a display name that starts with 'a' including a count of returned objects
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual
and the $count=true
query string because the request has both the $orderBy
and $filter
query parameters. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Note: The $count
and $search
query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName, 'a')&$count=true&$top=1&$orderby=displayName
ConsistencyLevel: eventual
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var groups = await graphClient.Groups
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("startswith(displayName, 'a')")
.OrderBy("displayName")
.Top(1)
.GetAsync();
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var contacts = await graphClient.Contacts
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("startswith(displayName,'A')")
.OrderBy("displayName")
.Top(1)
.GetAsync();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.header('ConsistencyLevel','eventual')
.filter('startswith(displayName, \'a\')')
.orderby('displayName')
.top(1)
.get();
const options = {
authProvider,
};
const client = Client.init(options);
let contacts = await client.api('/contacts')
.header('ConsistencyLevel','eventual')
.filter('startswith(displayName,\'A\')')
.orderby('displayName')
.top(1)
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$filter=startswith(displayName,%20'a')&$count=true&$top=1&$orderby=displayName"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/contacts?$filter=startswith(displayName,'A')&$count=true&$top=1&$orderby=displayName"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphOrgContact *orgContact = [[MSGraphOrgContact alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
GroupCollectionPage groups = graphClient.groups()
.buildRequest( requestOptions )
.filter("startswith(displayName, 'a')")
.orderBy("displayName")
.top(1)
.get();
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
OrgContactCollectionPage contacts = graphClient.contacts()
.buildRequest( requestOptions )
.filter("startswith(displayName,'A')")
.orderBy("displayName")
.top(1)
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Filter: "startswith(displayName,%20'a')",
Count: true,
Top: 1,
Orderby: "displayName",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.ContactsRequestBuilderGetQueryParameters{
Filter: "startswith(displayName,'A')",
Count: true,
Top: 1,
Orderby: "displayName",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.ContactsRequestBuilderGetOptions{
Q: requestParameters,
H: headers,
}
result, err := graphClient.Contacts().Get(options)
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Import-Module Microsoft.Graph.Groups
Get-MgGroup -Filter "startswith(displayName, 'a')" -CountVariable CountVar -Top 1 -Sort "displayName" -ConsistencyLevel eventual
Import-Module Microsoft.Graph.Identity.DirectoryManagement
Get-MgContact -Filter "startswith(displayName,'A')" -CountVariable CountVar -Top 1 -Sort "displayName" -ConsistencyLevel eventual
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups",
"@odata.count":1,
"value":[
{
"displayName":"a",
"mailNickname":"a241"
}
]
}
Example 5: Use $search to get groups with display names that contain the letters 'Video' including a count of returned objects
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual
because $search
is in the request. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Note: The $count
and $search
query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups?$search="displayName:Video"&$count=true
ConsistencyLevel: eventual
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups",
"@odata.count":1396,
"value":[
{
"displayName":"SFA Videos",
"mail":"SFAVideos@service.contoso.com",
"mailNickname":"SFAVideos"
}
]
}
Example 6: Use $search to get groups with display names that contain the letters 'Video' or a description that contains the letters 'prod' including a count of returned objects
Request
The following is an example of the request. This request requires the ConsistencyLevel header set to eventual
because $search
is in the request. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Note: The $count
and $search
query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups?$search="displayName:Video" OR "description:prod"&$orderby=displayName&$count=true
ConsistencyLevel: eventual
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#groups",
"@odata.count":1396,
"value":[
{
"displayName":"SFA Videos",
"mail":"SFAVideos@service.contoso.com",
"mailNickname":"SFAVideos"
},
{
"description":"Video Production",
"displayName":"Video Production",
"mail":"videoprod@service.contoso.com",
"mailNickname":"VideoProduction"
}
]
}
Example 7: List dynamic security groups
Request
The following is an example of the request that filters by the membershipRuleProcessingState to retrieve dynamic groups. You may also filter by the groupTypes properties (that is, $filter=groupTypes/any(s:s eq 'DynamicMembership')
). This request requires the ConsistencyLevel header set to eventual
and the $count=true
query string because the request uses the not
operator of the $filter
query parameter. For more information about the use of ConsistencyLevel and $count
, see Advanced query capabilities on Azure AD directory objects .
Note: The $count
and $search
query parameters are currently not available in Azure AD B2C tenants.
GET https://graph.microsoft.com/v1.0/groups?$filter=mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'&$count=true&$select=id,membershipRule,membershipRuleProcessingState
ConsistencyLevel: eventual
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var groups = await graphClient.Groups
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'")
.Select("id,membershipRule,membershipRuleProcessingState")
.GetAsync();
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var groups = await graphClient.Groups
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'")
.Select("id,membershipRule,membershipRuleProcessingState")
.GetAsync();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.header('ConsistencyLevel','eventual')
.filter('mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq \'Unified\')) and membershipRuleProcessingState eq \'On\'')
.select('id,membershipRule,membershipRuleProcessingState')
.get();
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.header('ConsistencyLevel','eventual')
.filter('mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq \'Unified\')) and membershipRuleProcessingState eq \'On\'')
.select('id,membershipRule,membershipRuleProcessingState')
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$filter=mailEnabled%20eq%20false%20and%20securityEnabled%20eq%20true%20and%20NOT(groupTypes/any(s:s%20eq%20'Unified'))%20and%20membershipRuleProcessingState%20eq%20'On'&$count=true&$select=id,membershipRule,membershipRuleProcessingState"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$filter=mailEnabled%20eq%20false%20and%20securityEnabled%20eq%20true%20and%20NOT(groupTypes/any(s:s%20eq%20'Unified'))%20and%20membershipRuleProcessingState%20eq%20'On'&$count=true&$select=id,membershipRule,membershipRuleProcessingState"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
GroupCollectionPage groups = graphClient.groups()
.buildRequest( requestOptions )
.filter("mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'")
.select("id,membershipRule,membershipRuleProcessingState")
.get();
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
GroupCollectionPage groups = graphClient.groups()
.buildRequest( requestOptions )
.filter("mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'")
.select("id,membershipRule,membershipRuleProcessingState")
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Filter: "mailEnabled%20eq%20false%20and%20securityEnabled%20eq%20true%20and%20NOT(groupTypes/any(s:s%20eq%20'Unified'))%20and%20membershipRuleProcessingState%20eq%20'On'",
Count: true,
Select: "id,membershipRule,membershipRuleProcessingState",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Filter: "mailEnabled%20eq%20false%20and%20securityEnabled%20eq%20true%20and%20NOT(groupTypes/any(s:s%20eq%20'Unified'))%20and%20membershipRuleProcessingState%20eq%20'On'",
Count: true,
Select: "id,membershipRule,membershipRuleProcessingState",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Import-Module Microsoft.Graph.Groups
Get-MgGroup -Filter "mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'" -CountVariable CountVar -Property "id,membershipRule,membershipRuleProcessingState" -ConsistencyLevel eventual
Import-Module Microsoft.Graph.Groups
Get-MgGroup -Filter "mailEnabled eq false and securityEnabled eq true and NOT(groupTypes/any(s:s eq 'Unified')) and membershipRuleProcessingState eq 'On'" -CountVariable CountVar -Property "id,membershipRule,membershipRuleProcessingState" -ConsistencyLevel eventual
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of the response.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups(id,membershipRule,membershipRuleProcessingState)",
"@odata.count": 1,
"value": [
{
"@odata.id": "https://graph.microsoft.com/v2/84841066-274d-4ec0-a5c1-276be684bdd3/directoryObjects/e9f4a701-e7b5-4401-a0ca-5bd5f3cdcf4b/Microsoft.DirectoryServices.Group",
"id": "e9f4a701-e7b5-4401-a0ca-5bd5f3cdcf4b",
"membershipRule": "(user.userType -contains \"Guest\" and user.accountEnabled -eq true) or (user.city -eq \"Nairobi\")",
"membershipRuleProcessingState": "On"
}
]
}
Example 7: List any groups with any licenses
Request
GET https://graph.microsoft.com/v1.0/groups?$select=id,assignedLicenses&$filter=assignedLicenses/any()
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var groups = await graphClient.Groups
.Request()
.Filter("assignedLicenses/any()")
.Select("id,assignedLicenses")
.GetAsync();
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var groups = await graphClient.Groups
.Request()
.Filter("assignedLicenses/any()")
.Select("id,assignedLicenses")
.GetAsync();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.filter('assignedLicenses/any()')
.select('id,assignedLicenses')
.get();
const options = {
authProvider,
};
const client = Client.init(options);
let groups = await client.api('/groups')
.filter('assignedLicenses/any()')
.select('id,assignedLicenses')
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$select=id,assignedLicenses&$filter=assignedLicenses/any()"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups?$select=id,assignedLicenses&$filter=assignedLicenses/any()"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphGroup *group = [[MSGraphGroup alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
GroupCollectionPage groups = graphClient.groups()
.buildRequest()
.filter("assignedLicenses/any()")
.select("id,assignedLicenses")
.get();
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
GroupCollectionPage groups = graphClient.groups()
.buildRequest()
.filter("assignedLicenses/any()")
.select("id,assignedLicenses")
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Select: "id,assignedLicenses",
Filter: "assignedLicenses/any()",
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.GroupsRequestBuilderGetQueryParameters{
Select: "id,assignedLicenses",
Filter: "assignedLicenses/any()",
}
options := &msgraphsdk.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
result, err := graphClient.Groups().GetWithRequestConfigurationAndResponseHandler(options, nil)
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Import-Module Microsoft.Graph.Groups
Get-MgGroup -Property "id,assignedLicenses" -Filter "assignedLicenses/any()"
Import-Module Microsoft.Graph.Groups
Get-MgGroup -Property "id,assignedLicenses" -Filter "assignedLicenses/any()"
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
The following is an example of the response.
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups(id,assignedLicenses)",
"value": [
{
"id": "5caf712c-8483-4b3d-8384-d8da988c0ca4",
"assignedLicenses": [
{
"disabledPlans": [],
"skuId": "6fd2c87f-b296-42f0-b197-1e91e994b900"
}
]
},
{
"id": "aae8ec2a-5a08-4013-ae70-fafbb5c20de1",
"assignedLicenses": [
{
"disabledPlans": [
"7547a3fe-08ee-4ccb-b430-5077c5041653"
],
"skuId": "18181a46-0d4e-45cd-891e-60aabd171b4e"
}
]
},
{
"id": "e55bdaa0-e104-479a-979e-b0457fff6380",
"assignedLicenses": [
{
"disabledPlans": [
"7547a3fe-08ee-4ccb-b430-5077c5041653"
],
"skuId": "6fd2c87f-b296-42f0-b197-1e91e994b900"
}
]
}
]
}