kwizcom banner advertisement

Sync-Update User Display Name from Active Directory to SharePoint using PowerShell

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.
Update User Display Name from in SharePoint using PowerShell

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 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 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|Crescent\michaelf" -web http://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="http://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)"
    }
}
Sync-Update User Display Name from Active Directory to SharePoint using PowerShell Sync-Update User Display Name from Active Directory to SharePoint using PowerShell Reviewed by Salaudeen Rajack on 1:02 PM Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.