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

Set user photo from Microsoft 365 to AD account

May 08, 2023 Views: 1307

The script gets a user photo from Microsoft 365 and sets it into the AD account of the user. To run the script, create a custom command or scheduled task configured for the User object type.

Edit Remove
# Get user ID in Microsoft 365
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")

# Connect to Exchange Online

# Get user photo
$picture = Get-UserPhoto $objectId.ToString() -ErrorAction SilentlyContinue

if ($NULL -eq $picture.PictureData)

# Update user photo in AD
$user = $Context.BindToObjectEx($Context.TargetObject.AdsPath, $True)
$user.Put("thumbnailPhoto", $picture.PictureData)
Comments 4
A Aug 31, 2021
I have this setup but is there a way to do a bulk import from 365 for all users
Support Sep 01, 2021

What exactly do you mean? Could you, please, describe the desired behavior in all the possible details with live examples?
Trent Jul 11, 2023
We would like to do this for all users, is that possible?
Support Jul 12, 2023
Hello Trent,

As it is mentioned in the script description, it can be executed in a scheduled task or custom command. As such, the easiest option is to create a one-time task executing the script and add All objects to the Activity Scope.
Leave a comment

Got questions?

Support Questions & Answers