Unable to sync user titles for Welcome name in SharePoint

Hello ,

If you facing this problem you may read my previous post.
http://blog.bugrapostaci.com/2011/06/22/sharepoint-2010-change-your-display-of-wellcome-name

In this post i have adding another powershell script that detects and fixes this problems for a workaround.

# THIS CODE-SAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
# FITNESS FOR A PARTICULAR PURPOSE.
<#

#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}

if( $args.Length -eq 0) {
write-host “Usage : Missing ”
exit
}

$MissMatchCount = 0
$NoProfile = 0;
$NoPrefferedName = 0
$TotalUser = 0
$Matched = 0
$Fixed = 0

write-host “Intializing…”
$site = new-object Microsoft.SharePoint.SPSite($args[0]);
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext);

foreach($siteUser in $site.RootWeb.SiteUsers)
{
write-host “Checking -> AccountName: ” $siteUser.LoginName ” ID:” $siteUser.ID
try
{
$profile = $ProfileManager.GetUserProfile($siteUser.LoginName);
}
catch
{
write-host “Unable to get profile for user” $siteUser.LoginName -foregroundcolor red
$NoProfile++
$TotalUser++
Write-host “————-”
continue;
}

$AccountName= $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
$PreferredName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::PreferredName].Value

write-host “Profile Data -> Account: ” $AccountName ” DisplayName:” $siteUser.DisplayName ” PrefferedName:” $PreferredName

if( $accountName -ne $siteUser.LoginName)
{
write-host “Account MissMatch -> LoginName: ” $siteUser.LoginName ” Profile Account:” $AccountName -foregroundcolor red
}

if( $PreferredName -ne “NONE” )
{
if($PreferredName -ne $siteUser.DisplayName)
{
write-host “MissMatch :” $siteUser.LoginName ” DisplayName:” $siteUser.DisplayName ” PrefferedName:” $PreferredName -foregroundcolor yellow
$MissMatchCount++

#Set-SPUser -identity $siteUser.LoginName -Displayname $PreferredName -web $args[0]
#$Fixed++
}
else
{
Write-host “OK”
$Matched++
}
}
else
{
$NoPrefferedName++
}
Write-host “————-”
$TotalUser++
}

Write-host “Results”
write-host “Total User : ” $TotalUser
write-host “Total Matched User Count : ” $Matched
write-host “Total Fixed User Count : ” $Fixed
Write-host “Total Missmatch User Count : ” $MissMatchCount
Write-host “Total Missing Profile User Count : ” $NoProfile
write-host “Total Empty Preffered Name user Count : ” $NoPrefferedName

For fixing option just activate the line by deleting “#” charecter.

#Set-SPUser -identity $siteUser.LoginName -Displayname $PreferredName -web $args[0]
#$Fixed++

Usage is simple:
Save the script in your drive as ps1 file.

C:\> .\syncuser.ps1 <SiteUrl>
Exp
C:\> .\syncuser.ps1 http://blog.bugrapostaci.com

PS: To get output in a text file is a little tricky but you can do it like this.
Start a Command Prompt ( Not Powershell! )
Type following command
C:\> powershell .\syncuser.ps1 http://blog.bugrapostaci.com > .\results.txt

Advertisements

After restoring SharePoint profile databases some of users pictures are not shown.

Ok this is a very specific issue and it could happen rarely. So the problem is somehow your SharePoint User Profile Application (UPA) has corrupted and you had to restore an old database back and see that some of user pictures are not shown. While you check the Photo Store (MySite->User Photos->Profile Pictures) all users pictures are present but when you check one of the problematic user’s profile from UPA the pictureURL attribute is not set. You can mannually fix it by using UPA Manage User Profile page but what happen if you have hundreds of users.

So fixing this issue.

1)      Copy the fallowing script in to your c: drive and save the file name as  “UpdateMissingPictures.ps1

2)      Check the picture folder name in Mysite-> User Photos library because it is diffrent depend on installed language.For example in Turkish it is “Profil Resimleri” not “Profile Pictures.Change the bold field belowed script and correct according to your envoriment.

3)      Run SharePoint PowerShell Consol.

4)      For confirming and detecting which profile pictures link are broken run script with fallowing parameters.

5)      C:\> .\UpdateMissingPictures.ps1  <MYSITE Sitesi root url>  | out-file c:\results.txt
Example:
.\UpdateMissingPictures.ps1  http://mysite.bugrapostaci.com:4444  | out-file c:\results.txt
(With this paremeters the script can not change anything (yet 🙂 )

6)     If you see open the  Results.txt file you can find information listed as
i) No change needed profiles as
OK!
DOMAIN\User URL
ii) Profile picture broken Link accounts
Updatable !!! DOMAIN\User
iii) Profile picture is never exists ones:
            Missing !!! DOMAIN\User

7)   This script can able to updates only marked accounts as “Updatable” . For fixing picture url run script like:

C:\> .\UpdateMissingPictures.ps1  <MYSITE Sitesi root url>  -Update | out-file c:\results.txt
example:
.\UpdateMissingPictures.ps1  http://mysite.bugrapostaci.com:4444  -Update| out-file c:\results.txt

8)    What about the Missings !!! The missing ones should be uploaded by manually or used another script for Upload profile pictures by bulk upload.
This is out of our article’s scope.

9)     You can check the  Results.txt file and confirm that  Updated !!! profiles .

If everything is ok The missing user pictures will shown after refreshing caches.
For Search  you have to run a full crawl.

Here is the Script:

Param (
[parameter(Mandatory=$true)][string]$MySiteUrl, 
 [parameter(Mandatory=$false)][Switch]$Update
)

$mySiteHostSite = Get-SPSite $MySiteUrl
$mySiteHostWeb = $mySiteHostSite.OpenWeb()
$context = Get-SPServiceContext $mySiteHostSite
$spPhotosFolder = $mySiteHostWeb.GetFolder("User Photos")

$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

$AllProfiles = $ProfileManager.GetEnumerator()

foreach($profile in $AllProfiles)
{
$AccountName= $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
   if($profile["PictureURL"].Value -eq $null -or $profile["PictureURL"].Value -eq $null )
{
  $checkUrl =$spPhotosFolder.url +"/" + "Profile Pictures" + "/" + $AccountName.Replace("\","_") + "_MThumb.jpg"

  if($mySiteHostWeb.GetFile($checkURL).Exists)
  {
   if($Update)
   { 
    $profile["PictureURL"].Value = $mySiteHostWeb.Url + "/" + $checkurl
    $profile.Commit()
    "Updated!!! " + $AccountName  
    $mySiteHostWeb.Url + "/" + $checkurl
   }
   else
   {
    "Updatable!!! " + $AccountName 
   }
 }
  else
  {
   "Missing !!! " + $AccountName 
  }
}
else
{
  "OK! " + $AccountName + " " + $profile["PictureURL"].Value
}
}

$mySiteHostWeb.Dispose()
$mySiteHostSite.Dispose()

Could we create a second User Profile Service Application ?

Yes you can but ,
If you have only one server in your farm you can use just one User Profile Service Application (UPA) in this server because the windows Service of User Profile Syncronization Service just configurable only one UPA. So if you have more than one sharepoint server in your farm for example 3 server;  you can create more than 3 UPA but you can only syncronize 3 of them.

For Another scenario, i assume that you have only one server and already provisioned one UPA and configured the syncronization connection. After adding second UPA as you know you can not able to add any Sycronization connection for Second UPA . But if you stop CA-> Services On Server -> User Profile Syncronization Service and restart it will prompt you to select UPA options mean you can change the relation for specific UPA . Still only one UPA can able to sync for one server.