Upload Profile Photo with MS Graph API to Azure AD

Here I want to show you an example on how to upload a Profile Photo to your Azure AD Account with PowerShell and Graph API

If you are new to MS Graph API, I would recommend reading this Posts on my Blog: Use Microsoft Graph API with PowerShell – Part 1 » TechGuy


As a Preparation, we need to make sure we can connect to MS Graph API and get an Access Token, please visit my Blog Posts for this.

Second thing, we need a Photo of what we want to upload. The only limitation i have found, that the max Size should not be more than 100KB


The tricky part here was to transfer the Picture itself, which is different from other Graph API Cals. Here we use the “-Infile” Command from the “Invoke-WebRequest” CMDlet

$headers = @{
    "Authorization" = "Bearer $($tokenResponse.access_token)"
    "Content-type"  = "application/json"


$URLPhoto = "https://graph.microsoft.com/v1.0/users/$UPN/photo/$value" 
Invoke-WebRequest -uri $URLPhoto -Headers $headers -Method PUT -Infile $Photo -ContentType 'image/jpg'

Now Login to Azure AD or Office 365 User Portal and check your Photo.

Self Service with au2mator

With au2mator Self Service Portal, you are also able to provide this as a Self Service to your End Users or Servicdesk / Helpdesk.

GitHub: https://github.com/au2mator/Azure-Upload-User-Photo

3 thoughts on “Upload Profile Photo with MS Graph API to Azure AD”

  1. Hi Michael,

    in your above script, you use a non-declared variable $value in the following line:

    $URLPhoto = “https://graph.microsoft.com/v1.0/users/$UPN/photo/$value”

    What is the value of “$value”?

  2. Hi,
    just a short improvement. Escape $value with `$value. Otherwise Graph will send back an error: (405) Invalid method

    $URLPhoto = “https://graph.microsoft.com/v1.0/users/$UPN/photo/`$value”
    Invoke-WebRequest -uri $URLPhoto -Headers $headers -Method PUT -Infile $Photo -ContentType ‘image/jpg’


Leave a Comment

Your email address will not be published. Required fields are marked *