Today we have picture of all the users in a document library. https://site.url/.../username_jpg.jpg

I would like to use these pictures of them on mysite. Can I use powershell or something else that can export these images to the right user on mysite?

2 Answers 2


Does the solution provided here work for you?


from the link:

#My Site URL
$mySiteUrl = "http://mysite/"

#The part of the picture URL you are trying to find
$pictureLibUrl = "http://mysite/<YourPictureLibraryName>/"

#The internal name for PictureURL
$upPictureURLAttribute = "PictureURL"
#The internal name for Login
$LoginAttribute = "AccountName"

#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()

# url of web where picture library is located
$webUrl = "http://mysite"
$web = Get-SPWeb $webUrl

foreach ($userProfile in $profiles) {

  $userLogin = $userProfile[$LoginAttribute].Value.Split('\')[1]
  $newPictureURL = $pictureLibUrl + $userLogin + ".jpg"
  $file =  $web.GetFile($newPictureURL)
  if($file.Exists)  {      
      $userProfile[$upPictureURLAttribute].Value = $newPictureURL
 }  else {
      $userProfile[$upPictureURLAttribute].Value = $null
  }  $userProfile.Commit()
  write-host "User: " $userLogin " Picture: " $newPictureURL
  • 1
    Thanks a lot, I didn't have the patience to wait, so I started to craft my own script, which looked very similar to this one. And that is quite promising since I am not a powershell expert.
    – williamwmy
    Commented May 24, 2013 at 14:45

I made a very similar code to @TempaC s answer. Feel free to comment if someone see room for improvements. I have tested this and it worked for my case.

#Defining DocLib and MySite
$mySiteUrl = "https://mySite.url/"
$sourceWebURL = "https://site.url/"
$sourceListName = "ListName"

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

#Get the pictures from the list
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]

#Get All users from ProfileManager
$profiles = $profileManager.GetEnumerator()
foreach ($up in $profiles) {
    $spSourceItems = $spSourceList.Items | where {$_['NameOrTitle'] -eq $up["UserName"].Value + ".jpg"}
    if  ($spSourceItems){
        $picturepath = $sourceWebURL + $sourceListName + "/" + $up["UserName"].Value + ".jpg"
        if ($up["PictureURL"]){
            #If pictureURL already exsist
            #Do Something?
            #If pictureURL is null
            $up["PictureURL"].Value = $picturePath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.