Change user’s display name in SharePoint 2007 using Powershell

I had an unusual case this week where a SharePoint 2007 installation did not have User Profile Synchronization enabled, but we needed to refresh (or more specifically, just update) SharePoint’s version of that user account with updated information from Active Directory.  We had two scenarios: a user who had gotten married and had a new last name, but the old last name was being displayed in SharePoint; and a user who was only being displayed using their DOMAIN\User format rather than a more user friendly display name.  Both of these issues have to do with synchronizing Active Directory and SharePoint, and both were overcome using some simple Powershell commands.

Here’s what I learned along the way.

1. In a SharePoint content database, there is a table called UserInfo, which (no surprise) contains information about the users that have been granted permission to the SharePoint site collection or its sites.  When a user is added to a SharePoint group, for instance, a query is made to Active Directory for that account, and the record is created in UserInfo.

2.  The ‘People Picker’ control will display results from both Active Directory and the UserInfo table, with the UserInfo table taking a slight precedence.  In my case, where I had a user being shown with their DOMAIN\User formatted name, that value would display in the People Picker rather than the ‘Last, First’ variant of their name.

3.  Most of the guidance on the web assumes that the User Profile Synchronization is in place.  This was not the case in my situation since this was a public facing site and did not have My Sites.

The first thing I tried was to delete the user from the Site Collection, then re-add them to a group.  All this did was mark the user’s record in UserInfo as deleted, and when I re-added them it unmarked it.  There (so far as I could tell) was not a re-query to Active Directory that occurred as I would have hoped.

So, since it is well established that thou shall not touch the SharePoint content database directly, I set out to find a way to edit the UserInfo record through a sanctioned method.  And that, even for SharePoint 2007, was Powershell.

First, we need to load up the SharePoint Assemblies

> [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Then we connect to our site collection

> $site = New-Object Microsoft.SharePoint.SPSite("")

Then we get the root web of the site collection

> $web = $site.RootWeb

We then need to connect to the User Information List, which corresponds to the UserInfo table.

> $list = $web.Lists["User Information List"]

And now we can select out the individual user record we want to update.  We’ll filter on the Account field, which should match our Active Directory user information.

> $user = $list.Items | where {$_["Account"] -eq "DOMAIN\User"}

If you look at the details of the $user object, you’ll see it has both a Name and DisplayName property.  Don’t be fooled, however, these fields are read only.  The one we want is Title.

So, lets update the Title value for this user and save the changes.

> $user["Title"] = "Lastname, Firstname"

> $user.update()

To check, I go back to the site and refresh the User Information List page – and sure enough, the updated value is applied.

Finally, then, we need to clean up after ourselves and dispose of the SharePoint objects.

> $web.Dispose()

> $site.Dispose()

This same approach can be used to update a user’s email address in SharePoint.





2 responses to “Change user’s display name in SharePoint 2007 using Powershell”

  1. Larry W Virden Avatar
    Larry W Virden

    I am seeking a solution to a problem we are encountering relating to this topic.
    On our small farm, the user profile information is successfully being imported from Active Directory to SharePoint. Then, when I look at the userinfo information on a site collection, most of the information is there as well – with 2 exceptions.
    1. Only a subset of the users that I would expect to see in the table are there.
    2. The account field from the userinfo table does not change when it should. Sometimes a user changes names, etc. and their login account changes. The actual login field in the userinfo table does change. However, there is a second field, called the account field, and that is not always changing.

    The end result is that in some cases, a user will undergo an account change, and some time later take some action such as checking out a document. When they go back to access the document, they are told that it is checked out to their old login. Another case is if an InfoPath form uses the getUser() function, it returns the account value (the old login) rather than the current login.
    If I go to the site collection, and the new user login to a group on that site collection, remove the login from the group, and the user tries the action again, everything works.

    I would like to figure out if there is a way, with a variation of the above script, to get a list of the user accounts and logins when they differ between the user profile and the user info table.
    Of course, if there were a way to then make the change (similar to how the title is changed here) that would be great as well.

    When I display the userlist via the _catalogs/users/simple.aspx interface, then select a user with this problem, the fields are named Account and User Name. When I look in Central Admin and the user profile properties, I see fields called AccountName and UserName.

    So my question is
    1. what would I need to change so that I could select out just users whose account and user names differ
    2. what would I need to change so that I would be prompted before replacing the account name with the user name?

    Any ideas that would help would be appreciated.

  2. Jaison Avatar

    Dear Derek Smith,i’m using claim based authentication in my sharepoint site.The very first time,i could add users from roles and membership database.But,then i couldnt.When i select user from people picker it shows the error message “No exact match found membershipname|user”.Can u help me with this problem???
    thanks and regards
    Jaison Joy

Leave a Reply