Site users are not fetching for few sites in SharePoint Online

Amit Dimri 51 Reputation points
2022-12-02T06:31:52.497+00:00

Dear all,

We are trying to create an audit report where we want to check the permissions of certain users on all the sites in SharePoint Online.
However, I am getting an issue where the user present in the site is not fetched for some sites.

I tried the following approaches.

  1. REST API (/*api/web/siteusers) its not fetching the user for some sites despite the user is allowed permission on the site.
  2. Powershell (Get-SPOUser -Site $Site.Url | Where{$*.LoginName -eq $User_Detail})
  3. CSOM
    ( var users = web.SiteUsers;
    var groups = web.SiteGroups;
    }

Out of all three methods I am not getting the list of all users in a site.

Can you please suggest some other options?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,969 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,132 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 36,821 Reputation points Microsoft Vendor
    2022-12-05T02:00:13.29+00:00

    Hi @Amit Dimri
    The siteusers endpoint works by querying a hidden list called the User Information List. If a user has never logged into the site collection, or had never been referenced in the site collection in some other fashion, the user will not have an entry in the list, so as far as SharePoint is concerned, that user does not exist in the site, even if they may have access through an AD group. As an example, I granted an AD group permissions to my site & only the AD group showed up in the hidden User Information list not the users

    Besides logging into a site, certain other activities, like adding the user to a People field in the site, or, as you've discovered, checking permissions, will trigger the process to add the user to the site. The basic process to trigger this process via REST is to call the EnsureUser endpoint. This endpoint will return information about the requested user, adding them to the site if they're not already there.

    EnsureUser: https://msdn.microsoft.com/en-us/library/office/dn499819.aspx#bk_WebEnsureUser


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



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.