Sync / Update User Display Name from Active Directory to SharePoint using PowerShell
Problem:
We found discrepancies in user properties between AD and SharePoint. E.g. User’s display name property is updated in Active Directory. But SharePoint still shows the old display name for the user.
How to Sync User Display Name from Active Directory to SharePoint?
Ideally, a proper SharePoint user profile sync setup should avoid these kinds of issues. Use these PowerShell scripts to force updates from AD to SharePoint. We can use the PowerShell script to update the user’s display name. E.g.
Set-SPUser -Identity "i:0#.w|domain\username" -DisplayName "NewDisplayName" -Web https://sp-site
The above cmdlet updates the given user’s display name for the particular site. Let’s do it for all users of the site (subsite).
Sync All Users of a Site Collection from Active Directory:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Subsite URL
$SiteURL = "https://portal.crescent.com/Teams/globalfunctions/compliance/"
#Get all users of the subsite
$UsersColl = Get-SPUser -web $SiteURL -limit ALL
#Process each user
foreach($user in $UsersColl)
{
#Sync user from Active directory
$User | Set-SPUser -SyncFromAD -ErrorAction SilentlyContinue
Write-host -foregroundcolor green "Display Name for $($user.Name) updated"
}
PowerShell script to update display name of the user in all site collections in SharePoint:
This PowerShell script scans and updates the given user properties on 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, Let’s sync all properties, such as E-Mail, Department, Job Title, etc. from AD to SharePoint:
$User = Get-SPuser "i:0#.w|Crescent\michaelf" -web https://intranet.crescent.com
$User | Set-SPUser -SyncFromAD
Sync a particular user from AD in a Site Collection:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Parameters
$UserID="Crescent\Jaten" #Classic Authentication
$SiteURL="https://portal.crescent.com"
#Get All sites of the Site Collection
$Sites = Get-SPSite $SiteURL | Get-SPWeb -limit all
#Iterate through each site collection
ForEach ($Site in $Sites)
{
Write-host "Processing Site:"$Site.URL
#Try to Get the User from site collection
$User = Get-SPUser $UserID -web $Site.url -ErrorAction SilentlyContinue
if($User -ne $Null)
{
#Sync User
$User | Set-SPUser -SyncFromAD -ErrorAction SilentlyContinue
Write-host -foregroundcolor green "Display Name for $($user.Name) updated in Site $($site.url)"
}
}
Sync All User’s Properties from Active Directory 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)"
}
}
Set-SPUser -SyncFromAD ,Is this property work from SharePoint 2016 using Microsoft Identity Management server instead of Active Directory Import
Hi Rajack,
Thanks for sharing the information,
we are seeing an issue like when the AD Sync is performed on the scheduled monthly activity, we see the display name and email is changing, like Praveen Nal to userid C11xxxx and the email id is showing nothing.
Kindly Advise is there any mappings i need to set.
Regards,
Praveen
Chances are: The “Preferred Name” property is set to UserID field and AD account’s E-mail property is blank!