8

I need to query the entire user profile store and do multiple operations such as filtering based on one user profile property, sorting by another, and grouping on yet another. Is this possible using any client side API (CSOM/JSOM, REST, SOAP)?

If client side won't work for this situation, is it possible to write all the user profile data into a SharePoint list on a monthly timer job with SSOM or PowerShell? My requirement is to reduce server side coding whenever possible and to allow Power Users the ability to manipulate the display of this data down the road without needing Visual Studio.

This is on SharePoint Server 2013 Standard (so the Content Search Web Part is out of the question since it's not Enterprise).

10

For a client solution I would use the Search REST API. The grouping has to be done on the client, it depends on how you configure your Managed Properties. The trick with People is to pass the correct Result Source ID in the query:

For example:

http://mysite/_api/search/query?querytext='LastName:m*'&selectproperties='LastName,FirstName,WorkEmail,JobTitle,Path,PictureUrl,PreferredName,Department,AboutMe'&SourceId='b09a7990-05ea-4af9-81ef-edfab16c4e31'

Returns all users with a last name starting with "m" and returns the Properties LastName, FirstName, WorkEmail, JobTitle, etc. The SourceId parameter tells search to only return People.

  • Can't use search as it's SP Server Standard – Josey Feb 19 '14 at 16:20
  • SharePoint Server Standard and Enterprise have the exact same search features. Have you configured the Search Service Application? (Or do you mean that you are using Foundation?) – Matthew McDermott Feb 20 '14 at 18:20
  • There are differences in search features between standard and enterprise (5 total but the biggest is lack of CSWP on Standard) but regardless, I think you are right in that search based REST might work for this situation. I'll POC it and let you know. – Josey Feb 21 '14 at 21:32
  • OK, if you look at it that way there are, like Video Result Sources, etc. But nothing that should impact your search results. – Matthew McDermott Feb 22 '14 at 12:31
  • I wanted to update you on my POC. So the engineer on this project did not configure search to crawl people so REST will not work in this case. Additionally he didn't use any search templates so tweaking a search results web part's display templates will not work either... damit – Josey Mar 3 '14 at 14:50
6

Schedule a PowerShell script task schedule which goes through all the user profiles and writes to SharePoint List. You can also use PowerShell to perform ordering and sorting on the objects returned.

Note: the script below loops through all the user profiles, you can complete it by writing it your SharePoint List + Scheduling it as a Task.

 #Add SharePoint PowerShell SnapIn if not already added 
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { 
        Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
    } 


    $site = new-object Microsoft.SharePoint.SPSite("http://WebapplicationURL/");  
    $ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);  

    #Get UserProfileManager from the My Site Host Site context 
    $ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)    
    $AllProfiles = $ProfileManager.GetEnumerator()  

    foreach($profile in $AllProfiles)  
    {  
        $DisplayName = $profile.DisplayName  
        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value  


        #Here goes writing Logic to your SharePoint List + Check if account already existing in the SharePoint list then ignore writing.......
        write-host "Profile for account ", $AccountName 


    }  
    write-host "Finished." 
    $site.Dispose() 
  • This won't work client side. It has to be run on the server. – Matthew McDermott Feb 19 '14 at 11:44
  • My bad, I thought he said it was fine to run the PowerShell on server side. – Falak Mahmood Feb 20 '14 at 9:51
  • No, no! My bad, I totally skipped the section that says PowerShell is OK. Sorry! – Matthew McDermott Feb 20 '14 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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