Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Saturday, August 15, 2015

Powershell Script to Change the Display Name in SharePoint 2007

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("http://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()

No comments:

Post a Comment