Updating User Profile pictures with powershell on SP2010

I finally had the chance to play around with user profiles. My customer asked me if it was possible to have the pictures of all employees show up in their respective user profiles in SharePoint and this without uploading the pictures themselves because they already had a dedicated website with all the pictures available. So the only thing to try to figure out was if it was possible to specify a link to the picture on a different website.

The customer was able to give me a CSV file with about 20K lines in it with 2 fields: Username + url of the picture. Worth mentionning was that the url of the user picture was not saved in any Active Directory property of the user object, sow e could not get it from there using the User Profile import process.

As it turns out the User profile actually has a property called PictureUrl which is completed by SharePoint when you upload your profile picture. So the task at hand was to write a script that could read the CSV file and update the user profiles. I started out with the script of Phil Childs and ended up with the following script:


$CSVFile = "C:\Scripts\pictureurls.csv"
$mySiteUrl = "http://people.contoso.com"

#Connect to the User Profile Manager
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

#Read CSV file and process each line
$csv = import-csv -path $CSVFile
foreach ($line in $csv)
{
$up = $profileManager.GetUserProfile($line.UserName)
if ($up)
{
$up["PictureURL"].Value = $line.PictureUrl
$up.Commit()
write-host $up.DisplayName," --> ", $line.PictureUrl
}
if (!$up) {
write-host $line.UserName, " --> no profile found"
}
}

Now, I’m not a powershell expert (yet) so this script can probably be optimized or improved.

For my customer, we are planning to have this script adapted to check if the pictureUrl field has already been populated and only add the value when it is not and have it run on a regular basis. Ultimately my customer is looking into saving this picture url in Active Directory afterwhich we can play around with FIM to have it popluate the user profiles that way.

3 thoughts on “Updating User Profile pictures with powershell on SP2010

  1. A bit misleading title. Post is about changing URLs in profiles, but not updating / changing the actual pictures stored on some location, but it is a good post!

    Due to GDPR regulations I am searching for something that will let me remove profile picture of a person from certain location in Sharepoint online.

    I have cleared all the data in the profile so nothing is now visible but getting some troubles, as when admin goes to the location where all the profiles are, he will see that picture. The problem is location which is https://-my.sharepoint.com/User%20Photos/Forms/Thumbnails.aspx and there is a folder called “profile pictures”, and somehow cannot go into it to clear particular pictures.

    Do you have any ideas how to read/remvoe such items?

Leave a Reply to SharePointGuru14 Cancel reply

Your email address will not be published. Required fields are marked *