Thursday, June 12, 2014

Sync-Update User Display Name from Active Directory to SharePoint

Problem: Discrepancies in User's properties in AD and SharePoint. Say for E.g. User''s display name property updated in Active Directory. But SharePoint still shows the old display name for the user.

Solution: Ideally, a proper setup of SharePoint user profile sync should avoid these kind of issues. Use these PowerShell scripts to force update from AD to SharePoint.We can use PowerShell script to update display name of the user. E.g.

Set-SPUser -Identity "i:0#.w|domain\username" -DisplayName "NewDisplayName" –Web http://sp-site
The above cmdlet updates the given user's display name for the particular site. Lets do it for all site collections.

PowerShell script to update display name of the user on all site collections in SharePoint:
This PowerShell script scans and updates the given user properties in all sites.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$UserID = "i:0#.w|Crescent\MichaelF"
$NewDisplayName = "Michael Fisher"

#Get All Site Collections
$Sites = Get-SPSite -limit all

#Iterate through each site collection
foreach ($Site in $Sites)
{
    #Try to Get the User from site collection
    $User = Get-SPUser -identity $UserID -web $Site.url -ErrorAction SilentlyContinue

    #If User found
    If($user)
    {    
        #Update the Display Name of the user
        Set-SPUser -identity $user -DisplayName $NewDisplayName
        Write-host –foregroundcolor green "Display Name updated in Site  $($site.url)"
    }

}
While the above code sets only the given display name, Lets sync all properties, such as E-Mail, Department, Job Title, etc. from AD to SharePoint:
$User = Get-SPuser "i:0#.w|testcareexchang\michaelf" -web http://intranet.crescent.com 
$User | Set-SPUser -SyncFromAD
 
Sync All User's Properties in All Sites:
How about syncing all user properties in all SharePoint 2010 sites?
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get All Site Collections
$Sites = Get-SPSite -limit all

#Iterate through each site collection
foreach ($Site in $Sites)
{
    #Try to Get the User from site collection
    $UsersColl = Get-SPUser -web $Site.url

    #Process each user
    foreach($user in $UsersColl)
    {    
        $User | Set-SPUser -SyncFromAD -ErrorAction SilentlyContinue

        Write-host –foregroundcolor green "Display Name for $($user.Name) updated in Site  $($site.url)"
    }

}



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...