Thursday 20 February 2014

SharePoint’s hidden User Information List

Browsing the User Information List
The User Information List can be accessed (Only if you’re admin) via the browser by navigating to /_catalogs/users/simple.aspx or  /_catalogs/users/detail.aspx from your site. Ex:http://testthepulse/_catalogs/users/simple.aspx or http://testthepulse/_catalogs/users/detail.aspx
Write code to interact with the User Information List
If you want to interact with this list to set properties on a user (Probably only want to do this if you’re running WSS) you could do it like this:
// Instantiates the User Information List SPList userInformationList = SPContext.Current.Web.SiteUserInfoList; 
// Get the current user SPUser user = SPContext.Current.Web.EnsureUser(@"ZIMMERTobiasZimmergren");
// The actual User Information is within this SPListItem SPListItem userItem = userInformationList.Items.GetItemById(user.ID);
The above code will give you the SPListItem object which links to the currently logged in user (the one executing the request).
You can then work with the SPListItem object like normal to get or set the properties like this:
string pictureURL = userItem["Picture"].ToString();
User Information List Fields
Instead of writing out all the fields/columns availible, you can simply create a new Console Application and insert the following code in order to output all the fields names and internalnames:
 
 1a.png

 
 
You can write a PowerShell script(named ListWebUserInformationListItems.ps1) as following:
 
# Run with SharePoint 2010 Management Shell
$webUrl = Read-Host "Enter the web url"
$web = Get-SPWeb $webUrl
$list = $web.Lists["User Information List"]
$query = New-Object Microsoft.SharePoint.SPQuery
$queryCamlString = '<Query><OrderBy><FieldRef Name="Title" Ascending="True" /></OrderBy></Query>'
$query.Query = $queryCamlString
$userInformationListItems = $list.GetItems($query)
foreach($userInformationListItem in $userInformationListItems)
{
    echo $userInformationListItem.Title
}
Then execute the script and input the web url when console window display the "Enter the web url" message.
Note: You can use SPQuery the get the User Information List items which are the users in this web application. The users are not all the users in the farm. And if you add a ADGroup to the SharePoint, you will add the only one SharePoint user to user information list(The SharePoint User stand for the ADGroup, the ADUser in the ADGroup will not present to the user information list).
 
 
Get a list of all users that have been synchronized into SharePoint.

# Run with SharePoint 2010 Management Shell
$site = Get-SPSite "your URL"
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
foreach(($profile in $profiles)
{
    $displayName = $profile.DisplayName
}

source: http://zimmergren.net/technical/sharepoints-hidden-user-list-user-information-list  

2 comments: