If you call the following CSOM code snippet to get groups from a Site Collection:

  ClientContext clientContext = new ClientContext(siteCollectionUrl);
  var groups = clientContext.Web.SiteGroups;
  clientContext.Load(groups, grp => grp.Include(item => item.Users,
                         item => item.Id,
                         item => item.LoginName,
                         item => item.PrincipalType,
                         item => item.Title
  foreach (Group group in groups) {
      Console.WriteLine("Group: {0} {1}", group.Id, group.LoginName);
      foreach (var user in group.Users) {
          Console.WriteLine("  Inner-user: {0} {1}", user.Id, user.LoginName);

Will this return all Groups from the whole SharePoint site? Or do I need to worry about some sort of pagination?

  • Yes, It will return all groups belong to current site collection. For more details you can just go through this link, docs.microsoft.com/en-us/previous-versions/office/developer/… Aug 7, 2018 at 4:26
  • might as well convert this to answer so it will help others. thank you!! i noticed that it seemed to return all of them regardless how many groups there were (even with 10000's). seemed too good to be true. even on sharepoint online this will be the case? Aug 7, 2018 at 4:31

1 Answer 1


Yes, It will return all groups belong to current site collection. For more details you can just go through this link.

  • even for sharepoint online? Aug 7, 2018 at 4:35
  • Yes, It will work for SharePoint online as well, because it use CSOM to retrieve groups. But I am not sure that it has any limitation or not, Like maximum number of groups it's return. Aug 7, 2018 at 4:44
  • ok that's what the quesiton is getting after. will i ever have a time i'm not getting all the groups from this... because there is no "row limit" in the load query Aug 7, 2018 at 5:06
  • So, Are you saying that you didn't get all groups from site collection? this is for SharePoint online or on-premise! Aug 7, 2018 at 5:22
  • SharePoint on premise it seems to return all the groups. I'm just wondering for sharepoint online if i'm going to get some issue because the list is so huge Aug 7, 2018 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.