Caleb Seelhoff
Caleb Seelhoff

Reputation: 261

Microsoft Graph API, Exchange Online users photo remove

I have a powershell script that uses Microsoft's Graph API to successfully update a user's photo using:

$photo = ([byte[]](Get-Content 'C:\UpdatePhotos\some_photo.jpg' -Encoding byte))
Invoke-RestMethod -Headers @{Authorization = "Bearer $access_token"} -Uri "https://graph.microsoft.com/beta/users('$email_address')/photo/`$value" -Method Put -Body $photo -ContentType 'image/jpeg' 

This works well for me and better than the EXO powershell command: Set-UserPhoto because some of the users have not been migrated to O365 yet, and Set-UserPhoto fails if they have not been migrated to O365 yet. So the Graph API has been working well for me, but now I need to do the following:

How do I remove a user's photo with Graph API?

Essentially I am looking for the equivalent to Remove-UserPhoto, but it needs to work for all users, including those who have not yet been migrated to O365. Is there a way to use the 'Delete' method in Graph? Or perhaps update the photo to an empty value?

Upvotes: 1

Views: 1769

Answers (2)

Jan Hajek
Jan Hajek

Reputation: 668

As of today's announcement the DELETE method now works. Documentation doesn't reflect this, but finally can do this via Graph like DELETE https://graph.microsoft.com/v1.0/users/[email protected]/photo

Upvotes: 0

Dan Kershaw - MSFT
Dan Kershaw - MSFT

Reputation: 5838

Unfortunately, this operation is not supported through Microsoft Graph. So, it means that users can only update their photos, but not delete. I'm looking into whether we could do something to offer a DELETE capability.

In the meantime the (nasty) workaround is to upload a transparent 1x1 pixel size image.

Hope this helps,

Upvotes: 1

Related Questions