I want to update the profile picture in user profile in SharePoint online using PowerShell.

Has anyone implemented it?


I used this script to update both the on-premise Active Directory and Azure AD (which will replicate to the SharePoint Online User Profile).

Required: a bunch of user pictures, named "Displayname.jpg", for example "John Doe.jpg"

$cred = Get-Credential #your Office 365 admin account
$MSOLSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid//?proxyMethod=RPS -Credential $cred -Authentication Basic -AllowRedirection #connection string that allows files larger than 10kb
Import-PSSession $MSOLSession #start an MSOL session

gci 'C:\UserPhotos' | % { #loop over all the picture files
   $photo = ([System.IO.File]::ReadAllBytes($_.FullName)) #read the picture file
   $user = $_.BaseName #I'm using the basename as to search in AD
   $u = Get-ADUser -Filter {DisplayName -eq $user} | Set-ADUser -Replace @{thumbnailPhoto=$photo} #search the user in AD and set the picture on premise
   echo $u.userPrincipalname #to see some progress when executing
   Set-UserPhoto –Identity $u.userPrincipalname -PictureData $photo -Confirm:$false #upload and set the user picture in Azure AD
  • Hi Meon, Thank you for the reply. I want to update the profile picture of external users, like Hotmail user to whom i have given access on my site. – MJaiswal Aug 3 '16 at 6:57
  • I haven't tried this one yet, put the userPrincipalName of such an external user is formed like this: "name_hotmail.com#ext#@tenant.onmicrosoft.com" . I'm not sure though as external users are not licensed an thus some restrictions on what you can do might apply. – meon Sep 23 '16 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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