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.
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()