Bulk importing user profile photo can be a pain in the arse, imaging you have few thousand of employee photos to be imported into your SharePoint. This project could use you a lot of times. To make your life easier, I would like to share my PowerShell script which may save you all the unnecessary time.
Prerequisite for this PowerShell
- You must use SharePoint Farm Account or Account is Shell Admin that has rights to My Site Host content database
- User Photos named after Account Name of your employee.
- SharePoint 2010, 2013 and 2016 only.
- User Photos Picture Library is already created in your My Site Host. Why? Because if you are in a fresh environment, SharePoint will not provision this Picture Library. To create this. You can either go to your Profile Page and upload a dummy photo. or Create it via Site Content, if you are creating it manually, make sure you also create a “Profile Photos” Folder within your “User Photos” picture library.
How to use the script
- Download and Copy the script into your SharePoint Server.
- Open SharePoint Management PowerShell
- Navigate to your the PowerShell script folder where you store the downloaded PowerShell and a folder with all your employees photo. e.g. /MyScript/UploadUserPhoto.ps1 and /MyScript/Photos/loginuser1.jpg
- Run the PowerShell with the following
UploadUserPhoto.ps1 -MySiteHostUrl "<Url to your My Site Photos>"
- Once executed, there will be a “log.txt” file to show give you the number of user with photos and without photos.
Advanced – Understanding the PowerShell Script
The Bulk Import PowerShell that I did actually will establish User Profile Service call to get all user profiles. It loops all user profile and tries to find the user’s Photo (which is put inside “Photos” folder of the same folder). The script checks against the user profile Account Name field, which is also the user’s Active Directory login name.
Once it is found, it imports the picture into “Profile Photo” folder inside “User Photos” picture library sitting in My Site Host.
There is a certain fixed, photo file name that you need to do in order to leverage this OOTB PowerShell command to update the user profile Picture Url and also generate the 3 different size of Photos
Photo File Name Format 0c37852b-34d0-418e-91c6-2ac25af4be5b_[RECORD ID].jpg
The GUID is fixed, and it will work for all SharePoint environment, and the RECORD ID is actually coming from one of the property in each User Profile.
Once all pictures are uploaded following the right file name, the script execute
Update-SPProfilePhotoStore -MySiteHostLocation $MySiteHostUrl -CreateThumbnailsForImportedPhotos:$true
This will be done automatically (OOTB-cally) and all your user profile will be handled 🙂
If you find it helpful, comment and say “SharePoint Hurray!”
I have found several scripts that claim to do this. this is the first one that actually worked!!!
Rest assure all the scripts uploaded here is always tested before me publishing them.
:))))