Home

How can I delete SharePoint Online Profile Pictures programatically?

%3CLINGO-SUB%20id%3D%22lingo-sub-219222%22%20slang%3D%22en-US%22%3EHow%20can%20I%20delete%20SharePoint%20Online%20Profile%20Pictures%20programatically%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-219222%22%20slang%3D%22en-US%22%3E%3CP%3EDoes%20anyone%20know%20if%20there's%20a%20way%20to%20delete%20SharePoint%20Online%20Profile%20Pictures%20programmatically%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20On%20Premise%20SharePoint%2C%20I'm%20managing%20this%20via%20this%20PowerShell%20Scripts%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20Convert%20string%20%24objectSid%20to%20byte%20%24byteSID%3C%2FP%3E%3CP%3E%24sid%20%3D%20New-Object%20System.Security.Principal.SecurityIdentifier%20(%24objectSid)%3CBR%20%2F%3E%24byteSID%20%3D%20New-Object%20'byte%5B%5D'%20%24sid.BinaryLength%3CBR%20%2F%3E%24sid.GetBinaryForm(%24byteSID%2C%200)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24site%3Dnew-object%20Microsoft.SharePoint.SPSite(%22%3CA%20href%3D%22http%3A%2F%2Fonprem.sharepoint.local%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fonprem.sharepoint.local%3C%2FA%3E%22)%3C%2FP%3E%3CP%3E%24serviceContext%20%3D%20Get-SPServiceContext%20%24site%3C%2FP%3E%3CP%3E%24upm%20%3D%20new-object%20Microsoft.Office.Server.UserProfiles.UserProfileManager(%24serviceContext)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24Userprofile%20%3D%20%24upm.GetUserProfile(%24byteSID)%3C%2FP%3E%3CP%3E%3CSTRONG%3E%24Userprofile%5B%22PictureURL%22%5D.value%3D%24null%3C%2FSTRONG%3E%3CBR%20%2F%3E%24Userprofile.Commit()%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThese%20users%20does%20not%20have%20Exchange%20Online%20Mailboxes%2C%20so%20I%20cannot%20use%20Set-UserPhoto%3C%2FP%3E%3CP%3EI%20managed%20to%20upload%20photos%20using%20via%20this%20method%2C%20but%20I%20cannot%20remove%20the%20pictures%20once%20uploaded%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP%2Ftree%2Fmaster%2FSamples%2FCore.ProfilePictureUploader%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP%2Ftree%2Fmaster%2FSamples%2FCore.ProfilePictureUploader%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-219573%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20delete%20SharePoint%20Online%20Profile%20Pictures%20programatically%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-219573%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20try%20this%20pnp%20powershell%26nbsp%3Bscript%20to%20remove%20picture%20URL%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConnect-PnPOnline%20-Url%20https%3A%2F%2F%3CTENANTNAME%3E-admin.sharepoint.com%3CBR%20%2F%3Eset-PnPUserProfileProperty%20-Account%20alexw%40%3CTENANTNAME%3E.onmicrosoft.com%20-PropertyName%20%22PictureURL%22%20-Value%20%22%22%3C%2FTENANTNAME%3E%3C%2FTENANTNAME%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Jun Ye
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)

$Userprofile["PictureURL"].value=$null
$Userprofile.Commit()

 

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:

https://github.com/SharePoint/PnP/tree/master/Samples/Core.ProfilePictureUploader

 

1 Reply

You can try this pnp powershell script to remove picture URL

 

Connect-PnPOnline -Url https://<tenantname>-admin.sharepoint.com
set-PnPUserProfileProperty -Account alexw@<tenantname>.onmicrosoft.com -PropertyName "PictureURL" -Value ""

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies