Office 365 – Upload User Photo via PowerShell (Set-UserPhoto)
At first, We create session via commands(as below).
It is very important to add “?proxymethod=rps” to “ConnectUrl”
$User = "account@company.onmicrosoft.com"
$Password = ConvertTo-SecureString -String "password" -AsPlainText -Force
$UserCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
Execute the PowerShell Commands to upload photo
Set-UserPhoto -Identity exouser -PictureData ([System.IO.File]::ReadAllBytes("C:\photo\userphoto.jpg"))
After that, Logon on Office 365 Portal, click the user to open the detail page.
you could see the photo that have been uploaded. soon you also could see the photo on teams.
NOTE:
According to results that I implement
1.synchronized time will not exceed 48hrs.
2.if the photo is smaller than 256×256, the user photo on Office 365 Admin Portal
will be removed, but the photo on the Teams will be updated.
3.if the photo is bigger than 256×256, The photo will be updated on Office 365 admin Portal and Teams.
hope it helps