Set a user profile picture

  • Last update on August 8th, 2024

Table of Contents

Custom actions are not available in the Essentials solution.

 

Use the following CoreView custom action script to import user photos to Exchange in bulk through a SharePoint site.

Custom action script:

$myUrlSite = "https://<Domain>.sharepoint.com"
 $format = ".jpeg"
 #retrieve the current ps credential object from the sharepoint connection
 $cred = Get-PnPConnection
 #here you have to change the site context because we use the admin site when we open a Sharepoint connection
 Connect-PnPOnline -Url $myUrlSite -Credentials ($cred.PSCredential)
 $photos = @(Get-PnPFolderItem -FolderSiteRelativeUrl "photos" -ItemType File)
 foreach( $photo in $photos){
 if( $photo.Name.Contains("@<Domain name>.com")){
 $memoryStream = New-Object System.IO.MemoryStream
 $streamResult = $photo.OpenBinaryStream()
 Invoke-PnPQuery
 $streamResult.Value.CopyTo( $memoryStream)
 $imageArray = $memoryStream.ToArray()
 Set-UserPhoto -Identity $photo.Name.Replace($format, '') -PictureData $imageArray -Confirm: $false
 }
 }