Script repository

Export user photo to a file

Updated on: Jan 18, 2026, Views: 3310

Export data

The script exports a user’s photo stored in the thumbnailPhoto property to a file. To execute the script, create a custom command, business rule or scheduled task configured for the User object type.

In the script, the $filePath variable specifies a template for the path to the file that will contain the photo. You can use value references, (e.g. %username%) in the path.

$filePath = "\\Server\share\UserPictures\%username%.jpg" # TODO: modify me
try
{
    $thumbnailPhoto = $Context.TargetObject.Get("thumbnailPhoto")
}
catch
{
    return # The Picture property is empty
}
try
{
    Set-Content -Path $filePath -AsByteStream byte -Value $thumbnailPhoto -ErrorAction Stop
}
catch
{
    $Context.LogMessage($_.Exception.Message, "Error")
}

Comments 4

You must be signed in to comment.

  • Daniel Sadler

    Daniel Sadler

    Does this pull the info/photo from Office 365?

    • Support

      Support

      Hello Daniel,

      No, the script gets the photo from the Picture (LDAP name thumbnailPhoto) property of an on-premises AD account.

  • Keith

    Keith

    Just a note that this fails now that encoding a 'byte' has been deprecated as written.

    Instead, just replace -Encoding 'byte' with -AsByteStream and it works great.

    • Support

      Support

      Hello Keith,

      Thank you for pointing out the behavior. We updated the script accordingly.

Got questions?

Support Questions & Answers

We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.