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
PowerShell
# Get user ID in Microsoft 365
try
{
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    return
}

# Connect to Exchange Online
$Context.CloudServices.ConnectExchangeOnline()

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

if ($NULL -eq $picture.PictureData)
{
    return
}

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

What exactly do you mean? Could you, please, describe the desired behavior in all the possible details with live examples?
avatar
Trent Jul 11, 2023
We would like to do this for all users, is that possible?
avatar
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
Loading...

Got questions?

Support Questions & Answers