Bulk upload of profile pictures for SharePoint 2013. The script do not require property mapping and do not rewrites the PictureURL.A nice feature is that if the pictures are uploaded with this script the profile picture of the user will be with the largest thumbnail possible so you will have better picture resolution compared to the AD import.

Supports BMP, GIF, JPEG, PNG, TIFF, and WMF picture formats. Script should run in elevated process under the farm account!First you will need to run the script with GenerateCSV parameter. A CSV file will be generated where you can fill the path to the picture for the specific profile(using Excel or your editor of choice).Paths to the photos can be local or network. After you fill all the photo paths that you want. Run the script with UpdatePhotos parameter. The script will upload the photos and will run the native command Update-SPProfilePhotoStore to generate thumbnails and update the PictureURL.The script do not support multiple User Profile Service applications in single farm or partitioned User Profile Service application!

If you are running the script in a fresh SharePoint installation, make sure that User Photos library exist in your My Sites host and also that there is a folder in it called Profile Pictures. If no user has a profile picture most probably the folder is missing. You can create it manually or by uploading a profile picture for some account and the folder will be created as shown below.

If you are using SharePoint installation with language different than English. It is possible to have different name of the library and the photo folder in this case  please edit the Upload-ToUserPhotos function according, there you will find the name of the library, the folder and the upload method.

v1.1 - Parameter typo fixed, enhanced error handling. Support quoted picture path (Example "C:\somepic.png"). Actual exception message will be shown when an error occur.

You will find both versions in the file.

Please, test and use Q&A section!

Thanks to jlai79 !



For More information see the Help: Get-Help .\Upload-ProfilePhotos.ps1 -Full


Author: Ivan Yankulov

Contact: http://spyankulov.blogspot.com

About this script: http://spyankulov.blogspot.com/2014/08/bulk-upload-and-update-user-profile.html

 

 

PowerShell
Edit|Remove
#########################################################################  
#                  Sample Functions  
#              Full Code is in the File  
#########################################################################  
 
Function Upload-ToUserPhotos{ 
 [CmdletBinding()] 
 Param( 
     [parameter(Mandatory=$true)] 
    [string]$URL, 
    [parameter(Mandatory=$true)] 
    [string]$Path, 
    [parameter(Mandatory=$true)] 
    [string]$ID 
 ) 
 Process{ 
    $docLibraryName = "User Photos" 
    $docLibraryUrlName = "Profile%20Pictures" 
    $web = Get-SPWeb $URL 
    $docLibrary = $web.Lists[$docLibraryName] 
    $file = Get-Item $Path 
    #Open file 
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead() 
    #Add file 
    $folder =  $web.GetFolder($docLibraryUrlName) 
    $spFile = $folder.Files.Add("/" + "User%20Photos" + "/" + $folder.Url + "/" + "0c37852b-34d0-418e-91c6-2ac25af4be5b_" + $ID + ".jpg", [System.IO.Stream]$fileStream$true) 
    #Close file stream 
    $fileStream.Close(); 
    } 
} 
Function Update-Photos{ 
 [CmdletBinding()] 
 Param( 
     [parameter(Mandatory=$true)] 
    [string]$URL, 
    [parameter(Mandatory=$true)] 
    [string]$Path 
 ) 
Process{ 
    Try{ 
        $accountData = Import-Csv $Path -ErrorAction Stop 
    }Catch [System.Exception]{ 
        Throw "Unable to load the CSV file from path: `"$Path`"" 
    } 
    ForEach ($acc in ($accountData | Where {$_.PhotoPath.Length -ge 2} )) 
    { 
        If(Test-Path $acc.PhotoPath -ErrorAction SilentlyContinue) 
        { 
            If((Get-Item -Path $acc.PhotoPath).Extension -eq ".jpg") 
            {     
                Copy-Item -Path $acc.PhotoPath -Destination ($PSScriptRoot + "\tempPicture.jpg") 
                Try{ 
                    Upload-ToUserPhotos -ID $acc.RecordID -Path ($PSScriptRoot + "\tempPicture.jpg"-URL $URL -ErrorAction Stop 
                    Write-Host "Uploading picture for account: `"$($acc.LoginName)`"" -ForegroundColor Green 
                }Catch [System.Exception]{ 
                    Write-Host "Unable to upload the picture for account: `"$($acc.LoginName)`"" -ForegroundColor Red 
                } 
                Remove-Item -LiteralPath ($PSScriptRoot + "\tempPicture.jpg"-ErrorAction SilentlyContinue 
            } 
            Else 
            { 
                Copy-Item -Path $acc.PhotoPath -Destination ($PSScriptRoot + "\tempPicture.jpg") 
                $convertedFile = ($PSScriptRoot + "\convertedPicture.jpg") 
                Add-Type -AssemblyName system.drawing 
                $image = [drawing.image]::FromFile(($PSScriptRoot + "\tempPicture.jpg")) 
                $image.Save($convertedFile, [System.Drawing.Imaging.ImageFormat]::jpeg) 
                $image.Dispose() 
                Try{ 
                    Write-Host "Uploading picture for account: `"$($acc.LoginName)`"" -ForegroundColor Green 
                    Upload-ToUserPhotos -ID $acc.RecordID -Path $convertedFile -URL $URL -ErrorAction Stop 
                }Catch [System.Exception]{ 
                    Write-Host "Unable to upload the picture for account: `"$($acc.LoginName)`"" -ForegroundColor Red 
                } 
                Remove-Item $convertedFile -Force -ErrorAction SilentlyContinue 
                Remove-Item -LiteralPath ($PSScriptRoot + "\tempPicture.jpg"-ErrorAction SilentlyContinue 
            } 
        } 
        Else{ 
            Write-Host "Unable to get the picture for Account: $($acc.LoginName)" -ForegroundColor Red 
        } 
    } 
        Try{ 
            Write-Host "Updating Profile Photo Store...." -ForegroundColor Green 
            Update-SPProfilePhotoStore -MySiteHostLocation $URL -CreateThumbnailsForImportedPhotos:$true -ErrorAction Stop 
        }Catch [System.Exception]{ 
            Write-Host "Unable to updating Profile Photo Store !" 
        } 
} 
}