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.

Script Repository

Import user photo

February 18, 2021 Views: 3145

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers