Tuesday, July 23, 2013

Number of users in the User Profile service application

You can obtain the number of users in the user profile service application by opening the settings page for the service application inside of central administration.

To navigate to this page, open:
  • Central Administration
  • Next click "Application Management"
  • Then "Manage service applications"
  • Now, click on the name for the user profile service application
On the page that opens there is a total count of users in the upper right corner. 

Number of users in the user profile service application
Alternatively, you can also obtain this same count by using PowerShell. First obtain a UserProfileManager object:

$mySite_url = <Url to your My Site site collection>;
$context = Get-SPServiceContext $mySite_url;
$upm= New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
Write-Host($upm.Count);

Note: the script above must be run by as a user that has ShellAdmin rights. 

See this post on how to check if your current user has enough rights, and if needed how to grants the user ShellAdmin rights.

In SharePoint 2010 there might exist a bug in the count method for the UserProfileManager object. Under some circumstances count method will return a different number of profiles than what can be iterated over in a loop.

For example, to count all available profiles by iterating, run the following additional lines of PowerShell code:

$profiles = $upm.GetEnumerator();
$profiles.Reset();
$count = 0;
foreach($profile in $profiles) {$count++;}
Write-Host($count);

Sometimes $count will have a lesser value than what $upm.Count returns.

See this and this for additional information to what causes this issue.

No comments:

Post a Comment