Monday, October 22, 2012

Force a Single User’s Profile to Sync With Active Directory


Occasionally we will have a user that changes their last name and wants it to reflect the change across SharePoint.  In order to aid this process I wrote 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 (“DOMAN\User”).

$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"

1 comment:

  1. You are an awesome blogger. This is one of the best blog I had visited so far. Hope to read more post from you in the future. Keep it up. God bless.