Hello,
Here's the script that should do the job:
$userDirectoryPath = "\\server\share\UsersInfo" # TODO: modify me
$pictureFileName = "%username%.jpg" # TODO: modify me
# Get EmployeeId
try
{
$employeeId = $Context.TargetObject.Get("employeeID")
}
catch
{
return
}
# Build user folder path
$userDirectoryPath = "$userDirectoryPath\$employeeId"
# Test user folder path
if(!(Test-Path -Path $userDirectoryPath))
{
$Context.LogMessage("Folder $userDirectoryPath was not found.", "Error") # TODO: modify me
return
}
# Build user picture path
$picturePath = "$userDirectoryPath\$pictureFileName"
if(!(Test-Path -Path $picturePath))
{
$Context.LogMessage("The path to the user's picture is incorect.", "Error") # TODO: modify me
return
}
# Save picture to AD
[Byte[]]$pictureInByte = Get-Content $picturePath -Encoding Byte
$Context.TargetObject.Put("thumbnailPhoto", $pictureInByte)
$Context.TargetObject.SetInfo()
In the script, $userDirectoryPath specifies the path to the folder where subfolders with user pictures are located, and $pictureFileName specifies the template for generating the picture filename for each user. Modify the script to your requirements.
You can use the script in Business Rules, Custom Commands and Scheduled Tasks with the Run a program or PowerShell script action.