Script Repository

Import user photo

September 21, 2016

The script imports a user's photo into Active Directory from a file. To import user photos on demand, you can create a Custom Command that runs the script. To schedule import of user photos, create a Scheduled Task.

To add the script to your command or task, use the Run a program or PowerShell script action.


  • $picturePath - specifies the full path to the image file.

    You can use value references in the file path. When the script is executed, the value references are replaced with property values of the user on which it is executed. For example, if you specify \\SERVER\Share\%username%.png, and the script is executed on a user whose username is jdoe, the path will be \\server\share\Archive\jdoe.png.
Edit Remove
$picturePath = "\\SERVER\Share\%username%.png"  # TODO: modify me

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

# Save picture to AD
[Byte[]]$pictureBytes = Get-Content $picturePath -Encoding Byte
$Context.TargetObject.Put("thumbnailPhoto", $pictureBytes)

Comments ( 0 )
No results found.
Leave a comment