1

I need some function like bellow on CSOM. could you help me ?


if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { 
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
} 

$site = new-object Microsoft.SharePoint.SPSite("<<WebApplicationSiteUrl>>");  
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);  

$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  
    write-host "Profile for account ", $AccountName
}  
write-host "Finished." 
$site.Dispose()
1

1 Answer 1

0

Here is an working example with PeopleManager but you can loop for web.Siteusers . Also this msdn page will help you.

using (ClientContext clientContext = new ClientContext("<Your SP Site>"))
        {
            Web web = clientContext.Web;
            clientContext.Load(web);
            clientContext.Load(web.SiteUsers);
            clientContext.ExecuteQuery();

            UserCollection users = web.SiteUsers;
            PeopleManager peopleManager = new PeopleManager(clientContext);

            foreach (User user in users)
            {
                PersonProperties personProperties = peopleManager.GetPropertiesFor(user.LoginName);
                clientContext.Load(personProperties, p => p.AccountName, p => p.DisplayName, p => p.UserProfileProperties);
                clientContext.ExecuteQuery();

                Console.WriteLine(personProperties.DisplayName);
            }

            Console.ReadLine();
        }

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.