How can I delete SharePoint Online Profile Pictures programatically?

New Contributor

Does anyone know if there's a way to delete SharePoint Online Profile Pictures programmatically?


For On Premise SharePoint, I'm managing this via this PowerShell Scripts:


# Convert string $objectSid to byte $byteSID

$sid = New-Object System.Security.Principal.SecurityIdentifier ($objectSid)
$byteSID = New-Object 'byte[]' $sid.BinaryLength
$sid.GetBinaryForm($byteSID, 0)


$site=new-object Microsoft.SharePoint.SPSite("http://onprem.sharepoint.local")

$serviceContext = Get-SPServiceContext $site

$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)


$Userprofile = $upm.GetUserProfile($byteSID)



These users does not have Exchange Online Mailboxes, so I cannot use Set-UserPhoto

I managed to upload photos using via this method, but I cannot remove the pictures once uploaded:


1 Reply

You can try this pnp powershell script to remove picture URL


Connect-PnPOnline -Url https://<tenantname>
set-PnPUserProfileProperty -Account alexw@<tenantname> -PropertyName "PictureURL" -Value ""