0

I need to check the department of each user in the collection. What do I need to use to do that?

2

Try to create a visual web part via visual studio and use Server-side object model via C# and use this code to get all user profile list based on property

using (SPSite site = new SPSite("http://portal/"))
{
        ServerContext context = ServerContext.GetContext(site);
        UserProfileManager profileManager = new UserProfileManager(context);

        foreach (UserProfile profile in profileManager)
       {
             Console.WriteLine(profile[PropertyConstants.Department]);
       }
}

For more details check How to: Retrieve User Profile Properties

If you need to work with javascript object model Check also How to: Retrieve user profile properties by using the JavaScript object model in SharePoint 2013

If you need to use PowerShell

 #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 


    }  

    $site.Dispose() 

Ref : How to return all user profiles

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.