Script repository

Import user photo from file

Updated on: Jan 18, 2026, Views: 4333

Import data

The script imports a user photo into Active Directory from a file. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.

In the script, the $picturePath variable specifies the full path to the image file.

$picturePath = "\\SERVER\Share\%username%.jpg"  # TODO: modify me

# Check whether the picture file exists.
if(!(Test-Path -Path $picturePath))
{
    $Context.LogMessage("File does not exist '$picturePath'.", "Error")
    return
}

# Save picture to AD.
[Byte[]]$pictureBytes = [System.IO.File]::ReadAllBytes($picturePath)
$Context.TargetObject.Put("thumbnailPhoto", $pictureBytes)
$Context.TargetObject.SetInfo()

Comments 0

You must be signed in to comment.

    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.