Wednesday, 13 June 2018

Forcing Synchronization of Display Name and Email from Active Directory without User Profile Synchronization - PowerShell Script

Just made this script to Synchronize Display Name and Email for all users in a root web if they have been updated in AD and aren't flowing through to your display name in SharePoint. This may be required if the user profile service is not set up or is failing. This problem is discussed in more detail at https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#As discussed in https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c 

Write-Host  -ForegroundColor Yellow "-------------------Process Start---------------------------------------------------------------"
Write-Host  -ForegroundColor Yellow "This script will sync the AD display name and email from AD without running a user profile sync"
Write-Host  -ForegroundColor Yellow "As discussed in https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c" 
Write-Host  -ForegroundColor Yellow "-------------------Process Start---------------------------------------------------------------"

$stopWatch = [Diagnostics.Stopwatch]::StartNew()

$rootWeb = Get-SPWeb "https://demo01.berkeleyit.com/"
ForEach ($user in $rootWeb.AllUsers)
{
    Write-Host  -ForegroundColor Green "Syncing Email and DisplayName with Active Directory... for $user" 
    Set-SPUser -Web $rootWeb -identity $user.UserLogin -SyncFromAD
}

$stopWatch.Stop()

$timeTaken = $stopWatch.Elapsed

Write-Host  -ForegroundColor Yellow "-------------------Process Completed in $timeTaken second(s)------------------"