Sunday, October 21, 2012

TIP: Remove domain from username in SharePoint 2010

Introduction


Sometimes, in SharePoint 2010, the user will see his or her name displayed as [domain name]\username, rather than the [Full Name] saved in Active Directory. Such as:




This can become problematic when configuring views to conserve limited width, as the addition of the domain in the username display may add considerably to the column width needed:



One way to address this is to configure user profile synchronization, and this is the best way as it automates resolution of this issue.  See the References for links to helpful articles on how to implement this approach.  However, this approach may not always be desirable or even feasible in some environments.  A much simpler spot approach is to use PowerShell.

Using PowerShell commandlets, you can resolve this for one user or a bunch of users at one time.  Let's get started.

Procedure

1) Open the SharePoint 2010 Management Shell as Administrator.

2) Enter the command in the format:

Set-SPUser -Identity '[domain name]\[username]' -DisplayName '[full name]' -Web [url]


3) After the command completes, a new command prompt is display (no messages).

4) To verify whether the command worked, just refresh your page:


and




5) To update the display name for all users, you need to first get the SPUser object associated with your website, and then port the results into the Set-SPUser commandlet, like so:

Get-SPUser –Web [url] | Set-SPUser –SyncFromAD



6) Running this command will generate a number of errors appearing in the command shell.  These result from the command attempting to synchronize ALL accounts, including such accounts as System, Local Service, etc, which obviously won't work. 



Ignore these errors: it worked on the others.

Summary

In this Tip, you were shown how to easily and quickly resolve a user identity appearing in the form "[domain name]\username" rather than "[Full Name]".  You were also shown how to do this for all users of a website.

References


No comments: