Tags

, , ,

GETTING ALL PROFILES FROM USER PROFILE

By using browser, you can see the number of profiles or find a profile’s details by using browser but cannot get a list of all existing profiles (Username, Firstname, Lastname, Email, …).

Fortunately, there are some alternate ways to do that:

1. Using PowerShell

  • Loading necessary Assemblies

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("microsoft.sharepoint.portal")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("System.Web")

  • Getting the UserProfileManager instance

$site = get-SPSite <my_site_url>
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

  • Getting profiles
    • Using GetEnumerator() method:

$profiles = $profileManager.GetEnumerator()

    • Using GetUserProfile() method:

$count = $profileManager.Count;
foreach ( $i=0; $i -le $count; $i++ )
{
$profile = $profileManager.GetUserProfile($i);
# Do something
}

>>> Using 2 above methods only get active profiles. All profiles that are marked as deleted are ignored.

2. Using SQL Statement

If you have enough permission to access directly to User Profile database (ex: Profile_DB) in SQL Database Server, you can query data from dbo.UserProfile view:

SELECT * FROM dbo.UserProfile
--WHERE bDeleted = 1 -- only deleted profiles

Enjoy!!!
Nhat Phan
Advertisements