4

Are there a way to get all users imported in SharePoint 2013 with the user profile (not a foundation). I saw SiteUserInfoList but there are not all imported users.

How can I achieve this in client object js

Maybe are there a way to use standard people search and display all peoples?

Mohamed El-Qassas MVP
  • 45,382
  • 9
  • 53
  • 96
user1898765
  • 973
  • 5
  • 20
  • 44
  • 1
    here is reference that may help you. http://sharepoint.stackexchange.com/questions/150123/how-to-get-active-directory-groups-in-sharepoint-2013-using-client-object-mod – Sunil Sahu Sep 09 '16 at 14:44
  • Thanks . Regarding the link i cannot get users that aren't already connected in SP? – user1898765 Sep 09 '16 at 14:47

2 Answers2

3

I guess you have used the following to retrieve the User Profiles:

https://<your site URL>/_api/web/siteusers

In order to achieve this, you can simply use SharePoint Search Rest API. All you have make sure is that you need to use the below Source ID

B09A7990-05EA-4AF9-81EF-EDFAB16C4E31

Following is an example of using the SharePoint Search REST API which you can try:

enter image description here

https://<your site url>//_api/search/query?querytext=%27*%27&rowlimit=3&sourceid=%27B09A7990-05EA-4AF9-81EF-EDFAB16C4E31%27

Also to know more about SharePoint REST APIs, check the following site: http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html

And below is the site link where you can find out more about SharePoint REST API: https://dev.office.com/sharepoint/docs/general-development/sharepoint-search-rest-api-overview

Also, below is the site link from where you can get the list of all the resurlt source: http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/01/04/list-of-common-sharepoint-2013-result-source-ids.aspx

Anand
  • 1,745
  • 20
  • 49
1

Not sure if this is exactly what you're looking for but I used this CSOM code in Powershell to enumerate all users from the Profile Store and dump their details into a list. You could convert this into an SP.js script and run from inside a Script Editor or Content Editor WP.

  1. Create a list with fields for the properties you need
  2. Modify the script from $NewListItem to update the fields with whatever properties you require from $userprofile and $upp (they both have different properties, I've included the links for the namespace references); or do whatever else you need with the properties, like printing to screen

It can probably be optimised a fair bit but the runtime is pretty decent against O365 so should be better for on-premise.

#Import the required DLL
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")

# Set the root Mysite URL to get profiles from (i.e. your Mysite web app)
$msite = 'https://spe551120-my.sharepoint.com'

# Set the user to run the query. Must be a Sharepoint Admin.
$admin = 'user@tenant'

# Set the password.
$password = ConvertTo-SecureString "yourPassword" -AsPlainText -Force

#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($msite)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin,$password)
$context.Credentials = $credentials

#Fetch the users in Site Collection
$users = $context.Web.SiteUsers
$context.Load($users)
$context.ExecuteQuery()

#Create an Object [People Manager] to retrieve profile information
$people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context)
$userIndex = 1;

Foreach($user in $users)
{
    # The $userprofile object contains some properties
    # https://msdn.microsoft.com/en-gb/library/microsoft.sharepoint.client.userprofiles.personproperties_members.aspx 
        $userprofile = $people.GetPropertiesFor($user.LoginName)
        $context.Load($userprofile)
        $context.ExecuteQuery()

    # To get the more advanced properties for some reason we need to use this method
    # https://technet.microsoft.com/en-us/library/hh147513(v=office.14).aspx
    $upp = $userprofile.UserProfileProperties;

    # Load the list
    # Set the URL for the site where the target list lives
    $uSite = "https://spe551120.sharepoint.com"
    $uContext = New-Object Microsoft.SharePoint.Client.ClientContext($uSite)
    $ucredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
    $ucontext.Credentials = $ucredentials

    # Set the name of the list where profile info lives
    $DocLib = "DS_HaveYouMet"
    $List = $uContext.Web.Lists.GetByTitle($DocLib)
    $uContext.Load($List)
    $uContext.ExecuteQuery()

    # Create and populate list item - when setting a field via $NewListItem you need to use the Static Name of the field (i.e. what it was when first created), not the Display Name. Replace 'property' with whatever property of $userprofile or $upp you need (see class references for a list of available ones)
    $ListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
    $NewListItem = $List.AddItem($ListItemCreationInformation)
    $NewListItem["fieldName"] = property;
    $NewListItem.Update()
    $uContext.load($newlistitem)
    $uContext.ExecuteQuery()

    $userIndex = $userIndex + 1;
}
Thomas Gass
  • 1,318
  • 1
  • 12
  • 24