SharePoint CSOM ClientPeoplePickerSearchUser could not query normal user account

Ching Song Lim 41 Reputation points
2022-06-29T06:16:49+00:00

Background :
Currently using ClientPeoplePickerSearchUser(ClientContext, ClientPeoplePickerQueryParameters) web service to determine orphan user. If query returns empty, then user will be flagged as orphan user.
The program loops through the root site and all site collections to complete the scanning for the whole web application.

Problem :
There are list of users are flagged as Orphan User in other site collections, but not the root site collection based on logic above.

Troubleshooting :

  1. Checked, user accounts are active status in Active Directory.
  2. User can be searched in people picker from the root site.

Questions :

  1. Why these users not able to query by ClientPeoplePickerSearchUser(ClientContext, ClientPeoplePickerQueryParameters)

Please find the code snippet (userValue = UserDisplayName item from UserInformationList)
216001-image.png

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.
2,663 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 30,991 Reputation points Microsoft Vendor
    2022-06-30T05:57:32.23+00:00

    Hi @Ching Song Lim ,
    Per my test, I can search the users in current sites by following code. Please make a reference

    string userToFind = "userToFind"; //it may be full or partial name of the user    
    string webUrl = "<site url>";    
    string userName = "<user name>";    
    string password = "<password>";    
    SecureString passWord = new SecureString();    
        //creating the context of the SharePoint site    
        using(ClientContext clientCtx = new ClientContext(webUrl)) {    
            foreach(char c in password.ToCharArray())    
            passWord.AppendChar(c);    
            clientCtx.Credentials = new SharePointOnlineCredentials(userName, passWord);    
            clientCtx.ExecuteQuery();    
            //preparing the search query options    
            Microsoft.SharePoint.ApplicationPages.ClientPickerQuery.ClientPeoplePickerQueryParameters peoplePickerQuery = new Microsoft.SharePoint.ApplicationPages.ClientPickerQuery.ClientPeoplePickerQueryParameters();    
            peoplePickerQuery.AllowEmailAddresses = true;    
            peoplePickerQuery.AllowMultipleEntities = false;    
            peoplePickerQuery.ForceClaims = false;    
            peoplePickerQuery.MaximumEntitySuggestions = 60;    
            peoplePickerQuery.PrincipalType = Microsoft.SharePoint.Client.Utilities.PrincipalType.All;    
            peoplePickerQuery.PrincipalSource = Microsoft.SharePoint.Client.Utilities.PrincipalSource.All;    
            peoplePickerQuery.QueryString = userToFind;    
            peoplePickerQuery.AllUrlZones = true;    
            peoplePickerQuery.SharePointGroupID = 0;    
            peoplePickerQuery.WebApplicationID = new Guid("00000000-0000-0000-0000-000000000000");    
            //Using peoplepicker webservice and searchquery getting the matched userInformations from SharePoint    
            ClientResult < String > resultData = Microsoft.SharePoint.ApplicationPages.ClientPickerQuery.ClientPeoplePickerWebServiceInterface.ClientPeoplePickerSearchUser(clientCtx, peoplePickerQuery);    
            clientCtx.ExecuteQuery();    
    			}  
    

    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.