How To Force SharePoint to Sync with Active Directory

Occasionally I have a user that changes their last name (or we got it spelled wrong) and I need the change to reflect across SharePoint (why SP doesn’t do this by itself I have no idea). In order to aid this process I found this script to force a resynchronize of each instance of the user profile in the user information lists. The script accepts one argument, which is the username to resync in the format DOMAN\User. Create a new powershell file with a ps1 extension and paste the code below into it.

$webapps = Get-SPWebApplication
 foreach ($webapp in $webapps) {
 [string] $login = $args[0]
 $sites = get-spsite -Limit All -WebApplication $webapp
 foreach ($s in $sites) {
 write-host $s.url
 $w = $s.RootWeb;
 $u = get-SPUser -Web $w -limit all | Where-Object {$_.userlogin -eq $login}
 if ($u -ne $null) {
 write-host "`t$($w.url)"
 Set-SPUser $u -SyncFromAD
 write-host "`tUpdated"
 }
 }
 }

After running it, you may get a few errors but you’ll notice their display name and other info is updated.

Advertisements

Author: Helicopter Jeff

I'm a vinyl decal cutting and designing, Astrophotography and general photography capturing, RC helicopter/quad copter pilot, Arduino and Raspberry Pi hardware/software developer, network, scripting and troubleshooting ninja living in the metro NY area. I am passionate about my hobbies so much I do them for a living. There's nothing better than getting paid to do what you love.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s