Set-MgUserPhotoContent: Status 500 (InternalServerError) when uploading photo

Lukas Priwitzer 0 Reputation points
2025-01-20T09:29:49.72+00:00

Hi everybody,

we are currently facing the challenge, to sync the user photo in our local Active Directory to EntraID.

We disabled the possibility for users to change their photo in M365, because we want to manage the photos centraly and locally.

My first approach is a powershell script. I get each AD-User, save the content of $user.thumbnailPhoto as a file to get the picture and then upload it, using Set-MgUserPhotoContent.

It seemed to work fine, but for about a week, i am getting an error:

Set-MgUserPhotoContent : The JSON value could not be converted to Microsoft.People.Image.Services.AdminControls.SourceScenario. Path: $.Source | LineNumber: 0 | BytePositionInLine: 14.
Status: 500 (InternalServerError)
ErrorCode: EndpointUnhandledException
Date: 2025-01-20T08:52:08
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : adc10103-d6f3-482f-b237-d2e372957f00
client-request-id : 644686f0-4bd2-430a-b7e8-488cdf64d0c1
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"FR2PEPF000001E0"}}
Date : Mon, 20 Jan 2025 08:52:07 GMT
In C:\Users\test\Desktop\UserPhotoSync.ps1:24 Zeichen:1
+ Set-MgUserPhotoContent -UserId 3c21b6f4-e7fe-44a6-92c8-7edca76b5daf - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ UserId = 3c21...ontentType = }:<>f__AnonymousType67`4) [Set-MgUserPhotoContent_Set], Exception
+ FullyQualifiedErrorId : EndpointUnhandledException,Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set

In my test-script, I do the following: (UserID altered)

$ADUser = Get-ADUser -identity "test" -properties thumbnailPhoto
[System.Io.File]::WriteAllBytes("C:\temp\test.png", $ADUser.thumbnailphoto)
Set-MgUserPhotoContent -UserId 'test@test.de' -InFile "C:\temp\test.png"

Maybe there is a better way, than a script?
Can you configure the EntraID Sync to always sync the photo?

Any help is appretiated!
Greetings Lukas

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,895 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,765 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhil Nasalwai - MSFT 170 Reputation points Microsoft Vendor
    2025-01-27T14:05:55.13+00:00

    Hello Lukas Priwitzer,

    Thank you for reaching out to Microsoft!!

    A 500 internal server error usually referred as server-side issues. Try testing the respective Graph API in the Graph Explorer or try executing the request after some wait time which might help in fixing such issues.

    For the query is there a better way than a script i.e. configuring the EntraID Sync to always sync the photo, please find the below workaround which might help resolve the issue.

    If you prefer to manage user photos centrally and locally, you can configure EntraID Sync to synchronize user photos from Active Directory. Here's a high-level overview of the process:

    • Sign in to the Microsoft Entra Admin Center as a Hybrid Administrator.
    • Navigate to Identity>Hybrid Management>Microsoft Entra Connect>Cloud Sync.
    • Select New configuration and choose AD to Microsoft Entra ID sync.
    • Map the thumbnailPhoto attribute from Active Directory to the corresponding attribute in Microsoft Entra ID.
    • Test your configuration before deploying it.
    • Enable your configuration once everything is setup.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.