First, you can export all the users with my site pictures by using the below query against the user profile database and save it to a CSV file. This will be the backup and will also be used to iterate through user profiles with profile pictures.
SELECT NTName,PreferredName,PictureUrl
FROM UserProfile_Full WITH (NOLOCK)
WHERE bDeleted=0
AND LEN(PictureUrl)>0
Next, you can run the below PowerShell to reset the PictureUrl value of the User Profile by fetching user profiles as listed in the csv file. This would be way faster than enumerating each user profile and checking if PictureUrl value exists.
Try updating for one user profile and then go ahead with mass update.
#Load User Profile Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles");
#Add-PsSnapin Microsoft.SharePoint.PowerShell
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$svcContext = Get-SPServiceContext "<MySiteHostUrl>";
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($svcContext);
$UsersWithSPPictures = (Import-Csv "C:\UserProfilesWithPictures.csv");
$null = "";
foreach($user in $UsersWithSPPictures){
try{
#Get User Profile
$userprofile = $profileManager.GetUserProfile($user.NTName);
$PicUrl = $userprofile["PictureUrl"].Value;
Write-Host $userprofile["PictureUrl"].Value;
#Reset PictureUrl
$userprofile["PictureUrl"].Value = $null;
$userprofile.Commit();
Write-Host "Picture Url deleted for: " $user.NTName "Picture Url: " $userprofile["PictureUrl"].Value;
#Update Picture Url
Write-Host "Updating: " $PicUrl;
$userprofile["PictureUrl"].Value = $PicUrl;
$userprofile.Commit();
Write-Host "User Picture Url updated: " $userprofile["PictureUrl"];
}
catch [System.Exception]{
Write-Host $user.NTName: $_.Exception.Message;
}
}
-
Edited by
Guru Karnik
Wednesday, September 19, 2012 7:52 PM
-
Proposed as answer by
Ivan-LiuModerator
Thursday, September 20, 2012 6:55 AM
-
Marked as answer by
Qiao WeiMicrosoft contingent staff, Moderator
Friday, September 28, 2012 10:37 AM