Update SharePoint User Information List

By James|12/01/2016|,

Once a user logs onto SharePoint or is granted access to a site collection, their information is stored in the site collection user information list. You can view the list by accessing site_collection_url/_catalogs/users.  Unfortunately, if the user’s information is updated in Active Directory the changes are NOT updated in SharePoint.

Update Single User With Active Directory Data

If you only want to update a single user, the following PowerShell code will do it:

$user = Get-SPUser -Identity "domain\user_name" -Web http(s)://site_collection_url
Set-SPUser -Identity $user -SyncFromAD -Web http(s)://site_collection_url

Update All Users With Active Directory Data

If you want to update all users across all site collections:

ForEach ($Site in Get-SPSite -Limit All) {
  Get-SPUser –Web $Site.RootWeb|Set-SPUser –SyncFromAD
}

Update All Users With User Profile Service Data

If you have a working User Profile Service (UPS) that is synchronizing with Active Directory, we can leverage the data stored in UPS to update the site collection user information list.  The following script will update all site collection user information lists from data stored in the UPS:

#--------------------------------------------------------------------------------
# Name:               Sync-SPUserInfoList.ps1 v2
# Description:        This script will update all of the properties in the User
#                     Information List with from the UPS
# Usage:              Make sure the UPS is connected to the Central Admin WebApp
# By:                 Ivan Josipovic, Softlanding.ca
#--------------------------------------------------------------------------------

Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0
$ErrorActionPreference = "SilentlyContinue"

$PropertyMap=@(
  "Title,PreferredName,Display Name",
  "EMail,WorkEmail,EMail",
  "MobilePhone,CellPhone,Mobile Phone",
  "Notes,AboutMe,About Me",
  "SipAddress,WorkEmail,Sip Address",
  "Picture,PictureURL,Picture URL",
  "Department,Department,Department",
  "JobTitle,SPS-JobTitle,Job Title",
  "FirstName,FirstName,First Name",
  "LastName,LastName,Last Name",
  "WorkPhone,WorkPhone,Work Phone",
  "UserName,UserName,UserName",
  "WebSite,WebSite,WebSite",
  "SPSResponsibility,SPS-Responsibility,Ask About Me",
  "Office,Office,Office"
)

$Context = Get-SPServiceContext $(Get-SPWebApplication -IncludeCentralAdministration | ? {$_.IsAdministrationWebApplication}).Url
$ProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($Context)

If ($ProfileManager){
    ForEach ($Site in $(Get-SPSite -Limit All | ? {!$_.Url.Contains("Office_Viewing_Service_Cache")})){
        $RootWeb = $Site.RootWeb
        Write-Host $($Site.Url)
  
        ForEach ($User in $($RootWeb.SiteUsers)){
            If ($ProfileManager.UserExists($($User.UserLogin))){
                $UPUser = $ProfileManager.GetUserProfile($($User.UserLogin))
                $UserList = $RootWeb.SiteUserInfoList

                $Query = New-Object Microsoft.SharePoint.SPQuery
                $Query.Query = "<Where><Eq><FieldRef Name='Name' /><Value Type='Text'>$($User.UserLogin)</Value></Eq></Where>"
                $UserItem = $UserList.GetItems($Query)[0]

                ForEach ($Map in $PropertyMap){
                    $PropName = $Map.Split(',')[0]
                    $SiteProp = $UserItem[$PropName]
                    $UPSProp = $UPUser[$($Map.Split(',')[1])].Value
                    $DisplayName = $Map.Split(',')[2]

                    If ($PropName -eq "Notes"){  
                        Write-Host "$DisplayName Updated: $SiteProp - $($UPSProp[0].Replace("&nbsp;"," "))"
                        $UserItem[$PropName] = $($UPSProp[0].Replace("&nbsp;"," "))
                    }
                    ElseIf($PropName -eq "Picture"){
                        Write-Host "$DisplayName Updated: $($SiteProp.Split(",")[0]) - $($UPSProp[0])"
                        $UserItem[$PropName] = $UPSProp[0]
                    }
                    ElseIf($PropName -eq "SPSResponsibility"){
                        Write-Host "$DisplayName Updated: $SiteProp - $($UPSProp -join ', ')"
                        $UserItem[$PropName] = $($UPSProp -join ', ')
                    }
                    Else{
                        Write-Host "$DisplayName Updated: $SiteProp - $UPSProp"
                        $UserItem[$PropName] = $UPSProp
                    }
                }
                Write-Host "Saving: $($User.UserLogin)"
                $UserItem.SystemUpdate()
                Write-Host ""
            }
        }
        $RootWeb.Dispose()
        Write-Host ""
    }
}
Else{
    Write-Host -foreground red "Cant connect to the User Profile Service. Please make sure that the UPS is connected to the Central Administration Web Application. Also make sure that you have Administrator Rights to the User Profile Service"
}

Update Domain Login ID

One caveat is that a user's login ID will NOT be changed using any of the above methods.  If a user's Active Directory login ID is changed, use the STSADM migrateuser command.  For example, let's say you have user MYDOMAIN\user1.  The login ID is changed to MYDOMAIN\user2.  To update SharePoint, perform the following from an administrative command prompt:

STSADM -o migrateuser -oldlogin MYDOMAIN\user1 -newlogin MYDOMAIN\user2 -ignoresidhistory

If the login ID's have apostrophes, enclose them in quotes.  For example:

STSADM -o migrateuser -oldlogin "MYDOMAIN\user'1" -newlogin MYDOMAIN\user2 -ignoresidhistory

 

 

Copyright 2011 - 2024 The Lazy IT Admin | All Rights Reserved
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram