Script Repository


Import user photo

September 21, 2016
1844

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.

Parameter:

  • $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
PowerShell
$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")
    return
}

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

Comments ( 0 )
No results found.
Leave a comment