Profile Photo Sync SPO

%3CLINGO-SUB%20id%3D%22lingo-sub-78585%22%20slang%3D%22en-US%22%3EProfile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78585%22%20slang%3D%22en-US%22%3E%3CP%3EAs%20admin%2C%20I%20have%20added%20profile%20photos%20for%20everyone%20in%20my%20org%20through%20the%20O365%20admin%20portal.%20The%20photos%20are%20seen%20everywhere.%20Except%20on%20SharePoint.%20I%20am%20unable%20to%20upload%20photos%20for%20people%20on%20SPO.%20I%20have%20read%20in%20other%20posts%20that%20the%20photos%20are%20synced%20when%20each%20user%20visits%20their%20Delve%20page%20at%20least%20once.%20Now%2C%20I%20cannot%20expect%20every%20user%20to%20go%20to%20their%20Delve%20page%20to%20sync%20the%20profile%20photos%20to%20SharePoint.%20Is%20there%20another%20way%20for%20the%20admin%20to%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%20for%20any%20help!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-78585%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-81484%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-81484%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20need%20to%20run%20'Set-ExecutionPolicy%20RemoteSigned'%20first%20and%20you%20need%20to%20install%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-in%2Fdownload%2Fdetails.aspx%3Fid%3D42038%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3ECSOM%20https%3A%2F%2Fwww.microsoft.com%2Fen-in%2Fdownload%2Fdetails.aspx%3Fid%3D42038%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20please%20note%20that%20the%20user%20photos%20should%20be%20named%20as%20userprincipalname%20(email%20address)%20of%20the%20user%20to%20whom%20you%20need%20to%20upload%20photo.%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20you%20need%20to%20change%20the%20imput%20parameters%20in%20the%20script%20as%20mentioned%20and%20save%20as%20.ps1%20file%20and%20run%20it.%20This%20will%20update%20the%20user%20photos%20immediately.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-80867%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-80867%22%20slang%3D%22en-US%22%3E%3CP%3EI%20finally%20got%20it%20working.%20Both%20through%20Powershell%20and%20the%20UI.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EFor%20the%20UI%20option%3C%2FSTRONG%3E%20(easier%20compared%20to%20PS)%20%2C%20go%20to%20the%20sharepoint%20online%20admin%20center%20--%26gt%3B%20User%20Profiles%20(left%20nav)%20--%26gt%3B%20Manage%20User%20Profiles.%20Edit%20a%20users%20profile.%20If%20you%20can't%20upload%20a%20photo%2C%20then%20change%20the%26nbsp%3B%3C%2FP%3E%3CP%3EPicture%26nbsp%3BExchange%20Sync%20State%20to%200.%20Then%20save.%20Edit%20the%20profle%20again%2C%20and%20upload%20a%20photo%20for%20the%20user%20(10KB%20or%20less%20in%20size).%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3EFor%20Powershell%20option%2C%26nbsp%3B%3C%2FSTRONG%3EI%20followed%20%3CA%20href%3D%22http%3A%2F%2Fwindowsitpro.com%2Fblog%2Fsynchronizing-user-photos-across-office-365-workloads-isnt-easy%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ethis%20article%3C%2FA%3E.%20Make%20sure%20you%20have%20Microsoft%20Azure%20Active%20Directory%20Module%20for%20Windows%20Powershell%20installed.%20And%20module%20MSOnline%20should%20also%20be%20installed.%20Follow%20the%20steps%20in%20the%20screenshot%20from%20my%20previous%20reply%20in%20this%20post.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20the%20powershell%20option%2C%20it%20takes%20upto%2072%20hours%20to%20reflect%20the%20change.%20The%20UI%20option%20is%20almost%20instant.%20Just%20a%20few%20minutes%20delay.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-80781%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-80781%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20looks%20exactly%20what%20I'm%20looking%20for%20-%20but%20not%20being%20a%20big%26nbsp%3Bpowershell%20user%2C%20what%20is%20required%20for%20me%20to%20run%20this%20powershell%20script%3F%20What%20do%20I%20need%20to%20connect%20to%20first%20and%20how%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-80556%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-80556%22%20slang%3D%22en-US%22%3E%3CP%3EFollowing%20PowerShell%20script%20is%20used%20to%20instantly%20process%20and%20display%20profile%20picture%20in%20Exchange%20Online%20and%20SharePoint%20Online%20using%20%E2%80%9CSet-UserPhoto%E2%80%9D%20cmdlet%20and%20CSOM.%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3EBefore%20executing%20the%20following%20script%2C%20you%20need%20to%20modify%20the%20input%20parameters%20in%20the%20script%20with%20your%20own%20values%20as%20follows%2C%3CBR%20%2F%3E%26nbsp%3B%3CBR%20%2F%3EInput%20Parameters%3A%3CBR%20%2F%3E%24siteUrl%3D%20%22%3CA%20href%3D%22https%3A%2F%2Ftenantname-my.sharepoint.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftenantname-my.sharepoint.com%2F%3C%2FA%3E%22%3CBR%20%2F%3E%24username%3D%20%22admin%40tenantname.onmicrosoft.com%22%3CBR%20%2F%3E%24password%3D%20%22xxxxxxxx%22%3CBR%20%2F%3E%24folderpath%3D%20%22E%3A%5Cphoto%22%3CBR%20%2F%3E%24SPOAdminPortalUrl%3D%20%E2%80%9C%3CA%20href%3D%22https%3A%2F%2Ftenantname-admin.sharepoint.com%2F%E2%80%9D%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftenantname-admin.sharepoint.com%2F%E2%80%9D%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%23Add%20references%20to%20SharePoint%20client%20assemblies%20and%20authenticate%20to%20Office%20365%20site%20%E2%80%93%20required%20for%20CSOM%0AAdd-Type%20-Path%20(%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client%22).location)%0AAdd-Type%20-Path%20(%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.runtime%22).location)%0AAdd-Type%20-Path%20(%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.UserProfiles%22).location)%0AAdd-Type%20-AssemblyName%20System.Drawing%0A%0AFunction%20UpdateUserProfile()%0A%7B%0AParam(%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24targetAcc%2C%0A%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24PropertyName%2C%0A%0A%20%20%5BParameter(Mandatory%3D%24False)%5D%0A%20%20%5BString%5D%24Value%2C%20%0A%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24SPOAdminPortalUrl%2C%0A%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BSystem.Net.ICredentials%5D%24Creds%0A%0A)%0A%24ctx%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SPOAdminPortalUrl)%0A%24ctx.Credentials%20%3D%20%24Creds%0A%24peopleManager%20%3D%20New-Object%20Microsoft.SharePoint.Client.UserProfiles.PeopleManager(%24ctx)%0A%24targetAccount%20%3D%20(%22i%3A0%23.f%7Cmembership%7C%22%20%2B%20%24targetAcc)%0A%24peopleManager.SetSingleValueProfileProperty(%24targetAccount%2C%20%24PropertyName%2C%20%24Value)%0A%24ctx.ExecuteQuery()%0A%7D%0A%0AFunction%20UploadImage%20()%0A%7B%0AParam(%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24SiteURL%2C%0A%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24User%2C%0A%0A%20%20%5BParameter(Mandatory%3D%24False)%5D%0A%20%20%5BString%5D%24Password%2C%20%0A%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24Folder%2C%0A%0A%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%5BString%5D%24SPOAdminPortalUrl%0A%0A)%0A%0A%23Defualt%20Image%20library%20and%20Folder%20value%20%0A%24DocLibName%20%3D%22User%20Photos%22%0A%24foldername%3D%22Profile%20Pictures%22%0A%0A%23Connect%20Exchange%20online%20%0A%0A%24secstr%20%3D%20New-Object%20-TypeName%20System.Security.SecureString%0A%24password.ToCharArray()%20%7C%20ForEach-Object%20%7B%24secstr.AppendChar(%24_)%7D%0A%24cred%20%3D%20new-object%20-typename%20System.Management.Automation.PSCredential%20-argumentlist%20%24User%2C%20%24secstr%0A%24Session%20%3D%20New-PSSession%20-ConfigurationName%20Microsoft.Exchange%20-ConnectionUri%20https%3A%2F%2Foutlook.office365.com%2Fpowershell-liveid%2F%3FproxyMethod%3DRPS%20-Credential%20%24cred%20-Authentication%20Basic%20-AllowRedirection%0AImport-PSSession%20%24Session%0A%0A%24Securepass%20%3D%20ConvertTo-SecureString%20%24Password%20-AsPlainText%20-Force%0A%24Creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24User%2C%24Securepass)%0A%0A%23Bind%20to%20site%20collection%0A%24Context%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%0A%24Context.Credentials%20%3D%20%24Creds%0A%0A%23Retrieve%20list%0A%24List%20%3D%20%24Context.Web.Lists.GetByTitle(%24DocLibName)%0A%24Context.Load(%24List)%0A%24Context.Load(%24List.RootFolder)%0A%24Context.ExecuteQuery()%0A%24ServerRelativeUrlOfRootFolder%20%3D%20%24List.RootFolder.ServerRelativeUrl%0A%0A%24uploadFolderUrl%3D%20%20%24ServerRelativeUrlOfRootFolder%2B%22%2F%22%2B%24foldername%0A%24spoimagename%20%3D%20%40%7B%22_SThumb%22%20%3D%20%2248%22%3B%20%22_MThumb%22%20%3D%20%2272%22%3B%20%22_LThumb%22%20%3D%20%22200%22%7D%0A%23Upload%20file%0AForeach%20(%24File%20in%20(dir%20%24Folder%20-File))%0A%7B%0A%0A%23Upload%20image%20into%20Exchange%20online%20%0A%24PictureData%20%3D%20%24File.FullName%0A%24Identity%3D%24File.BaseName%0ASet-UserPhoto%20-Identity%20%24Identity%20-PictureData%20(%5BSystem.IO.File%5D%3A%3AReadAllBytes(%24PictureData))%20-Confirm%3A%24false%0AWrite-Host%20%22Exchange%20online%20image%20uploaded%20successful%20for%22%20%24Identity%20%20%0A%0A%24username%3D%24File.BaseName.Replace(%22%40%22%2C%20%22_%22).Replace(%22.%22%2C%20%22_%22)%0A%24Extension%20%3D%20%24File.Extension%0AForeach(%24imagename%20in%20%24spoimagename.GetEnumerator())%0A%7B%0A%23Covert%20image%20into%20different%20size%20of%20image%0A%24img%20%3D%20%5BSystem.Drawing.Image%5D%3A%3AFromFile((Get-Item%20%24PictureData))%0A%5Bint32%5D%24new_width%20%3D%20%24imagename.Value%0A%5Bint32%5D%24new_height%20%3D%20%24imagename.Value%0A%24img2%20%3D%20New-Object%20System.Drawing.Bitmap(%24new_width%2C%20%24new_height)%0A%24graph%20%3D%20%5BSystem.Drawing.Graphics%5D%3A%3AFromImage(%24img2)%0A%24graph.DrawImage(%24img%2C%200%2C%200%2C%20%24new_width%2C%20%24new_height)%0A%0A%23Covert%20image%20into%20memory%20stream%0A%24stream%20%3D%20New-Object%20-TypeName%20System.IO.MemoryStream%0A%24format%20%3D%20%5BSystem.Drawing.Imaging.ImageFormat%5D%3A%3AJpeg%0A%24img2.Save(%24stream%2C%20%24format)%0A%24streamseek%3D%24stream.Seek(0%2C%20%5BSystem.IO.SeekOrigin%5D%3A%3ABegin)%0A%0A%23Upload%20image%20into%20sharepoint%20online%0A%24FullFilename%3D%24username%2B%24imagename.Name%2B%24Extension%0A%24ImageRelativeURL%3D%22%2F%22%2B%24DocLibName%2B%22%2F%22%2B%24foldername%2B%22%2F%22%2B%24FullFilename%0A%24ModifiedRelativeURL%3D%24ImageRelativeURL.Replace(%22%20%22%2C%22%2520%22)%0A%5BMicrosoft.SharePoint.Client.File%5D%3A%3ASaveBinaryDirect(%24Context%2C%24ModifiedRelativeURL%2C%20%24stream%2C%20%24true)%0A%0A%7D%0AWrite-Host%20%22SharePoint%20online%20image%20uploaded%20successful%20for%22%20%24Identity%20%0A%23Change%20user%20Profile%20Property%20in%20Sharepoint%20onlne%20%0A%24PictureURL%3D%24SiteURL%2B%24DocLibName%2B%22%2F%22%2B%24foldername%2B%22%2F%22%2B%24username%2B%22_MThumb%22%2B%24Extension%0A%0AUpdateUserProfile%20-targetAcc%20%24Identity%20%20-PropertyName%20PictureURL%20%20-Value%20%24PictureURL%20-SPOAdminPortalUrl%20%24SPOAdminPortalUrl%20-Creds%20%24Creds%0A%0AUpdateUserProfile%20-targetAcc%20%24Identity%20%20-PropertyName%20SPS-PicturePlaceholderState%20-Value%200%20-SPOAdminPortalUrl%20%24SPOAdminPortalUrl%20-Creds%20%24Creds%0A%0AUpdateUserProfile%20-targetAcc%20%24Identity%20%20-PropertyName%20SPS-PictureExchangeSyncState%20-Value%200%20-SPOAdminPortalUrl%20%24SPOAdminPortalUrl%20-Creds%20%24Creds%0A%0AUpdateUserProfile%20-targetAcc%20%24Identity%20%20-PropertyName%20SPS-PictureTimestamp%20%20-Value%2063605901091%20-SPOAdminPortalUrl%20%24SPOAdminPortalUrl%20-Creds%20%24Creds%0A%0AWrite-Host%20%22Image%20processed%20successfully%20and%20ready%20to%20display%20for%22%20%24Identity%0A%7D%0A%0A%7D%0A%23Input%20parameter%0A%24siteUrl%3D%22https%3A%2F%2Ftenantname-my.sharepoint.com%2F%22%0A%24username%3D%20%22admin%40tenantname.onmicrosoft.com%22%20%0A%24password%3D%20%22pass%40word1%22%0A%24folderpath%3D%20%22E%3A%5Cphoto%22%0A%24SPOAdminPortalUrl%20%3D%20%22https%3A%2F%2Ftenantname-admin.sharepoint.com%2F%22%0A%0Auploadimage%20-SiteURL%20%24siteUrl%20-User%20%24username%20-Password%20%24password%20-Folder%20%24folderpath%20-SPOAdminPortalUrl%20%24SPOAdminPortalUrl%20%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78908%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78908%22%20slang%3D%22en-US%22%3E%3CP%3ESo%2C%20I%20set%20the%20user%20photo%20using%20Powershell.%20See%20screenshot.%20It%20ran%20without%20any%20errors.%20Now%2C%20when%20I%20go%20the%20sharepoint%20admin%20page%2C%20the%20photo%20for%20this%20particular%20user%20has%20not%20been%20set.%20See%20screenshot.%20Set-UserPhoto%20does%20not%20seem%20to%20set%20the%20profile%20photo%20in%20SharePoint.%20Any%20further%20help%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20990px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F16070i3EB2744026652879%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22UserPhoto%20Error.png%22%20title%3D%22UserPhoto%20Error.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20739px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F16071i78680EBE03DFFBD1%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22UserPhoto%20Error1.png%22%20title%3D%22UserPhoto%20Error1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78623%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78623%22%20slang%3D%22en-US%22%3ETake%20a%20look%20at%20the%20following%20articles%20where%20you%20will%20find%20different%20approaches%20to%20achieve%20this.%20Be%20ready%20to%20work%20with%20some%20PowerShell%3A%3CBR%20%2F%3E-%20%3CA%20href%3D%22https%3A%2F%2Fspbreed.wordpress.com%2F2015%2F11%2F06%2Fdemystifying-user-profile-picture-sync-in-office365%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fspbreed.wordpress.com%2F2015%2F11%2F06%2Fdemystifying-user-profile-picture-sync-in-office365%2F%3C%2FA%3E%3CBR%20%2F%3E-%20%3CA%20href%3D%22http%3A%2F%2Fwindowsitpro.com%2Fblog%2Fsynchronizing-user-photos-across-office-365-workloads-isnt-easy%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwindowsitpro.com%2Fblog%2Fsynchronizing-user-photos-across-office-365-workloads-isnt-easy%3C%2FA%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1556691%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1556691%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1547%22%20target%3D%22_blank%22%3E%40Santhosh%20Balakrishnan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20this%20code%20example.%3C%2FP%3E%3CP%3EMy%20image%20file%20was%20continually%20locked%20after%20the%20first%20edit.%20I%20was%20able%20to%20fix%20it%20by%20changing%20the%20following%20lines%20of%20code%20in%20case%20you%20want%20to%20include%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24graph%20%3D%20%5BSystem.Drawing.Graphics%5D%3A%3AFromImage(%24img2)%0A%24graph.DrawImage(%24img%2C%200%2C%200%2C%20%24new_width%2C%20%24new_height)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eto%20include%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24graph%20%3D%20%5BSystem.Drawing.Graphics%5D%3A%3AFromImage(%24img2)%0A%24graph.DrawImage(%24img%2C%200%2C%200%2C%20%24new_width%2C%20%24new_height)%0A%24img.Dispose()%3B%0A%24graph.Dispose()%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2037756%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2037756%22%20slang%3D%22en-US%22%3E%3CP%3EI%20got%20the%20script%20working%2C%20but%20I%20only%20updates%20for%20the%20current%20user.%26nbsp%3B%20I%20need%20it%20to%20update%20ALL%20users.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2298904%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2298904%22%20slang%3D%22en-US%22%3EPerfect%2C%20I%20was%20just%20looking%20for%20this%20solution.%20Thanks%20for%20sharing!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2299941%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2299941%22%20slang%3D%22en-US%22%3EBe%20careful%20when%20you%20do%20the%20All%20option%2C%20as%20I%20haven't%20put%20error%20handling%20in%20the%20code.%3CBR%20%2F%3ESo%20exceptions%20will%20occur%20if%20the%20Exchange%20Online%20mailbox%20does%20not%20have%20a%20profile%20picture.%3CBR%20%2F%3EAs%20I%20don't%20reset%20any%20of%20the%20variables%20in%20the%20for%20loop%2C%20you%20might%20accidentally%20have%20the%20previous%20person%20photo%20applied%20to%20the%20user%20without%20the%20profile%20picture%20in%20Exchange%20Online.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2296656%22%20slang%3D%22en-US%22%3ERe%3A%20Profile%20Photo%20Sync%20SPO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2296656%22%20slang%3D%22en-US%22%3E%3CP%3EI%20thought%20this%20might%20help%20others.%3C%2FP%3E%3CP%3EBased%20on%20a%20previous%20post%20I%20created%20this%20script%20to%20work%20with%20O365%20with%20MFA%20enabled.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20PowerShell%20script%20will%20allow%20you%20to%20sync%20a%20user%20profile%20photo%20from%20Exchange%20Online%20to%20Sharepoint%20Online.%3C%2FP%3E%3CP%3EYou%20can%20select%20a%20single%20email%20address%20or%20choose%20%22All%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEDIT%3A%20Added%20Try-Catch%20block%20around%20section%20for%20some%20error%20handling.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%23Add%20references%20to%20SharePoint%20client%20assemblies%20and%20authenticate%20to%20Office%20365%20site%20%C3%A2%E2%82%AC%E2%80%9C%20required%20for%20CSOM%0AAdd-Type%20-AssemblyName%20System.Drawing%0A%0AFunction%20UploadImage%20()%0A%7B%0A%20Param(%0A%20%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%20%5BString%5D%24SiteURL%2C%0A%0A%20%20%20%5BParameter(Mandatory%3D%24True)%5D%0A%20%20%20%5BString%5D%24SPOAdminPortalUrl%2C%0A%0A%20%20%20%5BParameter(Mandatory%3D%24True%2C%20HelpMessage%3D%22Enter%20user%20email%20address%20or%20All%20for%20all%20mailboxes%22)%5D%0A%20%20%20%5BString%5D%24UserEmail%0A%0A%20)%0A%0A%20%23Defualt%20Image%20library%20and%20Folder%20value%20%0A%20%24DocLibName%20%3D%22User%20Photos%22%0A%20%24foldername%3D%22Profile%20Pictures%22%0A%0A%20%20%20%20Connect-ExchangeOnline%0A%20%20%20%20%24siteConnection%20%3D%20Connect-PnPOnline%20-Url%20%24SiteURL%20%E2%80%93Interactive%20-ReturnConnection%0A%0A%20%20%20%20%23NOTE%3A%20there%20is%20a%20bug%20in%20Set-PnPUserProfileProperty%20in%20which%20the%20ConnectPnPOnline%20must%20connect%20with%20the%20UseWebLogin%20option%20%0A%20%20%20%20%23%20https%3A%2F%2Fgithub.com%2Fpnp%2Fpowershell%2Fissues%2F277%0A%20%20%20%20%24adminConnection%20%3D%20Connect-PnPOnline%20-Url%20%24SPOAdminPortalUrl%20%E2%80%93UseWebLogin%20-ReturnConnection%0A%0A%20%24spoimagename%20%3D%20%40%7B%22_SThumb%22%20%3D%20%2248%22%3B%20%22_MThumb%22%20%3D%20%2272%22%3B%20%22_LThumb%22%20%3D%20%22200%22%7D%0A%0A%0A%20%20%20%20%24allUserMailboxes%20%3D%20Get-Mailbox%20-ResultSize%20Unlimited%20-RecipientTypeDetails%20UserMailbox%0A%0A%20%20%20%20Foreach(%24mailbox%20in%20%24allUserMailboxes)%0A%20%20%20%20%7B%0A%0A%20%20%20%20%20%20%20%20if((%24mailbox.PrimarySmtpAddress%20-eq%20%24UserEmail)%20-or%20(%24UserEmail%20-eq%20%22All%22))%7B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%20%22Processing%20%22%20%24mailbox.PrimarySmtpAddress%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%7B%0A%20%20%20%20%20%20%20%20%20%20%23Download%20Image%20from%20Exchange%20online%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24photo%20%3D%20Get-UserPhoto%20-Identity%20%24mailbox.Identity%0A%20%20%20%20%20%20%20%20%20%20Write-Host%20%22Exchange%20online%20image%20downloaded%20successful%20for%22%20%24mailbox.PrimarySmtpAddress%0A%0A%20%20%20%20%20%20%20%20%20%20%24username%20%3D%20%24mailbox.PrimarySmtpAddress.Replace(%22%40%22%2C%20%22_%22).Replace(%22.%22%2C%20%22_%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%24Extension%20%3D%20%22.jpg%22%0A%20%20%20%20%20%20%20%20%20%20Foreach(%24imagename%20in%20%24spoimagename.GetEnumerator())%0A%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%23Covert%20image%20into%20different%20size%20of%20image%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24ms%20%3D%20new-object%20System.IO.MemoryStream(%2C%24photo.PictureData)%0A%20%20%20%20%20%20%20%20%20%20%20%24img%20%3D%20%5BSystem.Drawing.Image%5D%3A%3AFromStream(%24ms)%0A%20%20%20%20%20%20%20%20%20%20%20%5Bint32%5D%24new_width%20%3D%20%24imagename.Value%0A%20%20%20%20%20%20%20%20%20%20%20%5Bint32%5D%24new_height%20%3D%20%24imagename.Value%0A%20%20%20%20%20%20%20%20%20%20%20%24img2%20%3D%20New-Object%20System.Drawing.Bitmap(%24new_width%2C%20%24new_height)%0A%20%20%20%20%20%20%20%20%20%20%20%24graph%20%3D%20%5BSystem.Drawing.Graphics%5D%3A%3AFromImage(%24img2)%0A%20%20%20%20%20%20%20%20%20%20%20%24graph.DrawImage(%24img%2C%200%2C%200%2C%20%24new_width%2C%20%24new_height)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%23Covert%20image%20into%20memory%20stream%0A%20%20%20%20%20%20%20%20%20%20%20%24stream%20%3D%20New-Object%20-TypeName%20System.IO.MemoryStream%0A%20%20%20%20%20%20%20%20%20%20%20%24format%20%3D%20%5BSystem.Drawing.Imaging.ImageFormat%5D%3A%3AJpeg%0A%20%20%20%20%20%20%20%20%20%20%20%24img2.Save(%24stream%2C%20%24format)%0A%20%20%20%20%20%20%20%20%20%20%20%24streamseek%3D%24stream.Seek(0%2C%20%5BSystem.IO.SeekOrigin%5D%3A%3ABegin)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%23Upload%20image%20into%20sharepoint%20online%0A%20%20%20%20%20%20%20%20%20%20%20%24FullFilename%3D%24username%2B%24imagename.Name%2B%24Extension%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Add-PnPFile%20-Connection%20%24siteConnection%20-Folder%20%22User%20Photos%2FProfile%20Pictures%22%20-FileName%20%24FullFilename%20-Stream%20%24stream%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20Write-Host%20%22SharePoint%20online%20image%20uploaded%20successful%20for%22%20%24mailbox.PrimarySmtpAddress%0A%20%20%20%20%20%20%20%20%20%20%23Change%20user%20Profile%20Property%20in%20Sharepoint%20onlne%20%0A%20%20%20%20%20%20%20%20%20%20%24PictureURL%3D%24SiteURL%2B%24DocLibName%2B%22%2F%22%2B%24foldername%2B%22%2F%22%2B%24username%2B%22_MThumb%22%2B%24Extension%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Set-PnPUserProfileProperty%20-Connection%20%24adminConnection%20-Account%20%24mailbox.PrimarySmtpAddress%20-PropertyName%20PictureURL%20-Value%20%24PictureURL%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Set-PnPUserProfileProperty%20-Connection%20%24adminConnection%20-Account%20%24mailbox.PrimarySmtpAddress%20-PropertyName%20SPS-PicturePlaceholderState%20-Value%200%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Set-PnPUserProfileProperty%20-Connection%20%24adminConnection%20-Account%20%24mailbox.PrimarySmtpAddress%20-PropertyName%20SPS-PictureExchangeSyncState%20-Value%200%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Set-PnPUserProfileProperty%20-Connection%20%24adminConnection%20-Account%20%24mailbox.PrimarySmtpAddress%20-PropertyName%20SPS-PictureTimestamp%20-Value%2063605901091%0A%0A%20%20%20%20%20%20%20%20%20%20Write-Host%20%22Image%20processed%20successfully%20and%20ready%20to%20display%20for%22%20%24mailbox.PrimarySmtpAddress%0A%20%20%20%20%20%20%20%20%20%20%20%20%7Dcatch%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24ErrorMessage%20%3D%20%24_.Exception.Message%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%20%22Failed%20to%20process%20%22%20%24mailbox.PrimarySmtpAddress%20-ForegroundColor%20red%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%20%24ErrorMessage%20-ForegroundColor%20red%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%7D%20%20%20%20%20%20%20%20%0A%0A%20%20%20%20%7D%0A%0A%7D%0A%0A%23Input%20parameter%0A%24siteUrl%3D%22https%3A%2F%2Fcompany-my.sharepoint.com%2F%22%0A%24SPOAdminPortalUrl%20%3D%20%22https%3A%2F%2Fcompany-admin.sharepoint.com%2F%22%0A%0Auploadimage%20-SiteURL%20%24siteUrl%20-SPOAdminPortalUrl%20%24SPOAdminPortalUrl%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

As admin, I have added profile photos for everyone in my org through the O365 admin portal. The photos are seen everywhere. Except on SharePoint. I am unable to upload photos for people on SPO. I have read in other posts that the photos are synced when each user visits their Delve page at least once. Now, I cannot expect every user to go to their Delve page to sync the profile photos to SharePoint. Is there another way for the admin to do this?

 

Many thanks for any help!

11 Replies
Take a look at the following articles where you will find different approaches to achieve this. Be ready to work with some PowerShell:
- https://spbreed.wordpress.com/2015/11/06/demystifying-user-profile-picture-sync-in-office365/
- http://windowsitpro.com/blog/synchronizing-user-photos-across-office-365-workloads-isnt-easy

So, I set the user photo using Powershell. See screenshot. It ran without any errors. Now, when I go the sharepoint admin page, the photo for this particular user has not been set. See screenshot. Set-UserPhoto does not seem to set the profile photo in SharePoint. Any further help?

UserPhoto Error.png


UserPhoto Error1.png

Following PowerShell script is used to instantly process and display profile picture in Exchange Online and SharePoint Online using “Set-UserPhoto” cmdlet and CSOM.
 
Before executing the following script, you need to modify the input parameters in the script with your own values as follows,
 
Input Parameters:
$siteUrl= "https://tenantname-my.sharepoint.com/"
$username= "admin@tenantname.onmicrosoft.com"
$password= "xxxxxxxx"
$folderpath= "E:\photo"
$SPOAdminPortalUrl= “https://tenantname-admin.sharepoint.com/”

 

#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location)
Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location)
Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles").location)
Add-Type -AssemblyName System.Drawing

Function UpdateUserProfile()
{
Param(
  [Parameter(Mandatory=$True)]
  [String]$targetAcc,

  [Parameter(Mandatory=$True)]
  [String]$PropertyName,

  [Parameter(Mandatory=$False)]
  [String]$Value, 

  [Parameter(Mandatory=$True)]
  [String]$SPOAdminPortalUrl,

  [Parameter(Mandatory=$True)]
  [System.Net.ICredentials]$Creds

)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOAdminPortalUrl)
$ctx.Credentials = $Creds
$peopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($ctx)
$targetAccount = ("i:0#.f|membership|" + $targetAcc)
$peopleManager.SetSingleValueProfileProperty($targetAccount, $PropertyName, $Value)
$ctx.ExecuteQuery()
}

Function UploadImage ()
{
Param(
  [Parameter(Mandatory=$True)]
  [String]$SiteURL,

  [Parameter(Mandatory=$True)]
  [String]$User,

  [Parameter(Mandatory=$False)]
  [String]$Password, 

  [Parameter(Mandatory=$True)]
  [String]$Folder,

  [Parameter(Mandatory=$True)]
  [String]$SPOAdminPortalUrl

)

#Defualt Image library and Folder value 
$DocLibName ="User Photos"
$foldername="Profile Pictures"

#Connect Exchange online 

$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $User, $secstr
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxyMethod=RPS -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

$Securepass = ConvertTo-SecureString $Password -AsPlainText -Force
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Securepass)

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Creds

#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List)
$Context.Load($List.RootFolder)
$Context.ExecuteQuery()
$ServerRelativeUrlOfRootFolder = $List.RootFolder.ServerRelativeUrl

$uploadFolderUrl=  $ServerRelativeUrlOfRootFolder+"/"+$foldername
$spoimagename = @{"_SThumb" = "48"; "_MThumb" = "72"; "_LThumb" = "200"}
#Upload file
Foreach ($File in (dir $Folder -File))
{

#Upload image into Exchange online 
$PictureData = $File.FullName
$Identity=$File.BaseName
Set-UserPhoto -Identity $Identity -PictureData ([System.IO.File]::ReadAllBytes($PictureData)) -Confirm:$false
Write-Host "Exchange online image uploaded successful for" $Identity  

$username=$File.BaseName.Replace("@", "_").Replace(".", "_")
$Extension = $File.Extension
Foreach($imagename in $spoimagename.GetEnumerator())
{
#Covert image into different size of image
$img = [System.Drawing.Image]::FromFile((Get-Item $PictureData))
[int32]$new_width = $imagename.Value
[int32]$new_height = $imagename.Value
$img2 = New-Object System.Drawing.Bitmap($new_width, $new_height)
$graph = [System.Drawing.Graphics]::FromImage($img2)
$graph.DrawImage($img, 0, 0, $new_width, $new_height)

#Covert image into memory stream
$stream = New-Object -TypeName System.IO.MemoryStream
$format = [System.Drawing.Imaging.ImageFormat]::Jpeg
$img2.Save($stream, $format)
$streamseek=$stream.Seek(0, [System.IO.SeekOrigin]::Begin)

#Upload image into sharepoint online
$FullFilename=$username+$imagename.Name+$Extension
$ImageRelativeURL="/"+$DocLibName+"/"+$foldername+"/"+$FullFilename
$ModifiedRelativeURL=$ImageRelativeURL.Replace(" ","%20")
[Microsoft.SharePoint.Client.File]::SaveBinaryDirect($Context,$ModifiedRelativeURL, $stream, $true)

}
Write-Host "SharePoint online image uploaded successful for" $Identity 
#Change user Profile Property in Sharepoint onlne 
$PictureURL=$SiteURL+$DocLibName+"/"+$foldername+"/"+$username+"_MThumb"+$Extension

UpdateUserProfile -targetAcc $Identity  -PropertyName PictureURL  -Value $PictureURL -SPOAdminPortalUrl $SPOAdminPortalUrl -Creds $Creds

UpdateUserProfile -targetAcc $Identity  -PropertyName SPS-PicturePlaceholderState -Value 0 -SPOAdminPortalUrl $SPOAdminPortalUrl -Creds $Creds

UpdateUserProfile -targetAcc $Identity  -PropertyName SPS-PictureExchangeSyncState -Value 0 -SPOAdminPortalUrl $SPOAdminPortalUrl -Creds $Creds

UpdateUserProfile -targetAcc $Identity  -PropertyName SPS-PictureTimestamp  -Value 63605901091 -SPOAdminPortalUrl $SPOAdminPortalUrl -Creds $Creds

Write-Host "Image processed successfully and ready to display for" $Identity
}

}
#Input parameter
$siteUrl="https://tenantname-my.sharepoint.com/"
$username= "admin@tenantname.onmicrosoft.com" 
$password= "pass@word1"
$folderpath= "E:\photo"
$SPOAdminPortalUrl = "https://tenantname-admin.sharepoint.com/"

uploadimage -SiteURL $siteUrl -User $username -Password $password -Folder $folderpath -SPOAdminPortalUrl $SPOAdminPortalUrl 

This looks exactly what I'm looking for - but not being a big powershell user, what is required for me to run this powershell script? What do I need to connect to first and how?

I finally got it working. Both through Powershell and the UI. 

 

For the UI option (easier compared to PS) , go to the sharepoint online admin center --> User Profiles (left nav) --> Manage User Profiles. Edit a users profile. If you can't upload a photo, then change the 

Picture Exchange Sync State to 0. Then save. Edit the profle again, and upload a photo for the user (10KB or less in size). 

For Powershell option, I followed this article. Make sure you have Microsoft Azure Active Directory Module for Windows Powershell installed. And module MSOnline should also be installed. Follow the steps in the screenshot from my previous reply in this post. 

For the powershell option, it takes upto 72 hours to reflect the change. The UI option is almost instant. Just a few minutes delay. 

You need to run 'Set-ExecutionPolicy RemoteSigned' first and you need to install CSOM https://www.microsoft.com/en-in/download/details.aspx?id=42038

 

Also please note that the user photos should be named as userprincipalname (email address) of the user to whom you need to upload photo. 

Now you need to change the imput parameters in the script as mentioned and save as .ps1 file and run it. This will update the user photos immediately.

@Santhosh Balakrishnan 

 

Thank you for this code example.

My image file was continually locked after the first edit. I was able to fix it by changing the following lines of code in case you want to include this.

 

$graph = [System.Drawing.Graphics]::FromImage($img2)
$graph.DrawImage($img, 0, 0, $new_width, $new_height)

 

to include

 

$graph = [System.Drawing.Graphics]::FromImage($img2)
$graph.DrawImage($img, 0, 0, $new_width, $new_height)
$img.Dispose();
$graph.Dispose();

  

I got the script working, but I only updates for the current user.  I need it to update ALL users.

 

I thought this might help others.

Based on a previous post I created this script to work with O365 with MFA enabled.

 

This PowerShell script will allow you to sync a user profile photo from Exchange Online to Sharepoint Online.

You can select a single email address or choose "All"

 

EDIT: Added Try-Catch block around section for some error handling.

 

#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -AssemblyName System.Drawing

Function UploadImage ()
{
	Param(
	  [Parameter(Mandatory=$True)]
	  [String]$SiteURL,

	  [Parameter(Mandatory=$True)]
	  [String]$SPOAdminPortalUrl,

	  [Parameter(Mandatory=$True, HelpMessage="Enter user email address or All for all mailboxes")]
	  [String]$UserEmail

	)

	#Defualt Image library and Folder value 
	$DocLibName ="User Photos"
	$foldername="Profile Pictures"

    Connect-ExchangeOnline
    $siteConnection = Connect-PnPOnline -Url $SiteURL –Interactive -ReturnConnection

    #NOTE: there is a bug in Set-PnPUserProfileProperty in which the ConnectPnPOnline must connect with the UseWebLogin option 
    # https://github.com/pnp/powershell/issues/277
    $adminConnection = Connect-PnPOnline -Url $SPOAdminPortalUrl –UseWebLogin -ReturnConnection

	$spoimagename = @{"_SThumb" = "48"; "_MThumb" = "72"; "_LThumb" = "200"}


    $allUserMailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox

    Foreach($mailbox in $allUserMailboxes)
    {

        if(($mailbox.PrimarySmtpAddress -eq $UserEmail) -or ($UserEmail -eq "All")){

            Write-Host "Processing " $mailbox.PrimarySmtpAddress

            try{
		        #Download Image from Exchange online 
                $photo = Get-UserPhoto -Identity $mailbox.Identity
		        Write-Host "Exchange online image downloaded successful for" $mailbox.PrimarySmtpAddress

		        $username = $mailbox.PrimarySmtpAddress.Replace("@", "_").Replace(".", "_")

		        $Extension = ".jpg"
		        Foreach($imagename in $spoimagename.GetEnumerator())
		        {
			        #Covert image into different size of image
                    $ms = new-object System.IO.MemoryStream(,$photo.PictureData)
			        $img = [System.Drawing.Image]::FromStream($ms)
			        [int32]$new_width = $imagename.Value
			        [int32]$new_height = $imagename.Value
			        $img2 = New-Object System.Drawing.Bitmap($new_width, $new_height)
			        $graph = [System.Drawing.Graphics]::FromImage($img2)
			        $graph.DrawImage($img, 0, 0, $new_width, $new_height)

			        #Covert image into memory stream
			        $stream = New-Object -TypeName System.IO.MemoryStream
			        $format = [System.Drawing.Imaging.ImageFormat]::Jpeg
			        $img2.Save($stream, $format)
			        $streamseek=$stream.Seek(0, [System.IO.SeekOrigin]::Begin)

			        #Upload image into sharepoint online
			        $FullFilename=$username+$imagename.Name+$Extension
                    Add-PnPFile -Connection $siteConnection -Folder "User Photos/Profile Pictures" -FileName $FullFilename -Stream $stream                                

		        }
		        Write-Host "SharePoint online image uploaded successful for" $mailbox.PrimarySmtpAddress
		        #Change user Profile Property in Sharepoint onlne 
		        $PictureURL=$SiteURL+$DocLibName+"/"+$foldername+"/"+$username+"_MThumb"+$Extension

                Set-PnPUserProfileProperty -Connection $adminConnection -Account $mailbox.PrimarySmtpAddress -PropertyName PictureURL -Value $PictureURL

                Set-PnPUserProfileProperty -Connection $adminConnection -Account $mailbox.PrimarySmtpAddress -PropertyName SPS-PicturePlaceholderState -Value 0

                Set-PnPUserProfileProperty -Connection $adminConnection -Account $mailbox.PrimarySmtpAddress -PropertyName SPS-PictureExchangeSyncState -Value 0

                Set-PnPUserProfileProperty -Connection $adminConnection -Account $mailbox.PrimarySmtpAddress -PropertyName SPS-PictureTimestamp -Value 63605901091

		        Write-Host "Image processed successfully and ready to display for" $mailbox.PrimarySmtpAddress
            }catch{
                $ErrorMessage = $_.Exception.Message
                Write-Host "Failed to process " $mailbox.PrimarySmtpAddress -ForegroundColor red
                Write-Host $ErrorMessage -ForegroundColor red
            }
	    }        

    }

}

#Input parameter
$siteUrl="https://company-my.sharepoint.com/"
$SPOAdminPortalUrl = "https://company-admin.sharepoint.com/"

uploadimage -SiteURL $siteUrl -SPOAdminPortalUrl $SPOAdminPortalUrl

 

 

Perfect, I was just looking for this solution. Thanks for sharing!
Be careful when you do the All option, as I haven't put error handling in the code.
So exceptions will occur if the Exchange Online mailbox does not have a profile picture.
As I don't reset any of the variables in the for loop, you might accidentally have the previous person photo applied to the user without the profile picture in Exchange Online.