Bulk upload of Profile Pictures using PowerShell
I have a client who has a lot of users but we set up their SharePoint environment for them, so they had a requirement that when they go live with SharePoint that the User Profiles are already setup with pictures etc. Since they had a large number of users, and didn’t want to do this manually, I wrote a PowerShell script that will upload the profile pictures to the MySite host, and then link them to the user’s profile.
Some caveats that I have come across while developing the solution:
- The user account used to run the script must have full control administrator permissions on the User Profile Service Application
- The user account used to run the script must have ShellAdmin rights in Powershell
- You can’t use the account used to install SharePoint, even if it is a farm account
- The account used to run the script must also be a Farm account
- The pictures used should be in either jpg or png format. You can use bmp files but the organogram doesn’t work well with bmp files
so lets get cracking.
Ensuring ShellAdmin rights
There are three different PowerShell commands you can use to manage the ShellAdmin permissions:
- get-SPShellAdmin
- add-SPShellAdmin
- remove-SPShellAdmin
to grant ShellAdmin permssions you use the following command:
add-SPShellAdmin –username <username> eg: add-SPShellAdmin –username sps2010-farm
you don’t need to include the domain. You can also just type add-SPShellAdmin and hit enter, and powershell will prompt you for the username:
to check if the user you want to add already has permissions, just type get-SPShellAdmin and you will get a list of the users with the permissions. To remove you use remove-SPShellAdmin, just like the add command, it will prompt you for the username.\
User Profile Service Application administrators
The account that will be used to run the script must be an administrator with “Full Control” permissions on the Profile Service Application.
Browse to “Manage Service applications” in Central Administration. Select the Profile Service application so that the ribbon is activated:
Click on “Administrators”:
Ensure that your account is added and has “Full Control” permissions:
Also remember to make sure that the account is a Farm Administrator.
Upload User Profile Pictures
A couple of things must be done before we can run the script:
- Create a SharePoint list with the usernames and filenames
- Store all the photos in a central folder on the servers harddrive
- update the configuration variables in the script
I will just show snippets of the script for now, but will attach the list template, and full script at the end.
PhotoUpload List
This list is straight forward custom list, with two columns:
- Filename – single line of text
- username – single line of text
For now, you must create this list in the root site of a site collection. for example:
if my SharePoint URL is www.mysite.co.za, which points to my root site collection, my list url is www.mysite.co.za/Lists/PhotoUpload/.
below is a sample of the list with data:
I have made the assumption that all the files listed in the list will be stored on the server where you are running the script from.
The Script
So lets update the script with your environment details:
#Please ensure the variables below are correct for your environment $domain = "<yourdomain>" $PhotosFolderPath = "<local folder with the files>" $siteCollectionURL = "<the location of the root site collection with the photo list>" $MySiteUrl = "<URL of your MySiteHost>" $listName = "<name of the list that contains the photos and users>" $Overwrite = $true # end of environment variables
This is pretty self-explanatory, but the one thing i must talk about here is the $Overwrite = $true. This will cause the script to overwrite any photos that exist for the users in the SharePoint list. This is useful for when you want to update a user profile picture. If you want the script to only add photos to profiles that don’t have them, then replace $true with $false.
So once you have added all the details to the SharePoint list, put all the photos in the local folder on your server, and updated your environment variables in the script, all you need to do is run it.
So run “SharePoint 2010 Management shell” and browse to the folder where you have stored this script, and type in the following command:
./UploadProfilePictures.ps1
The script will give you continuous feedback while it runs, it also uses coloured text to indicate important messages:
- Green: This is just a notification that something has completed successfully.
- Yellow: this is used to indicate a warning: such as the profile already has a picture
- Red: indicates an issue, either the user specified doesn’t exist in Active Directory, or there was an error that cause the script to stop.
The script will pause for a bit at the end as it will call a function that runs through the User Profile pictures and create the correctly sized pictures of any new pictures added. This will ensure that no matter where the profile picture is displayed in SharePoint, it will look right. If this doesn’t run, you will get funny things happening with the profile pictures.
Files
Disclaimer:
Please read the disclaimer if you plan on using anything from this article.

