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.
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()
What exactly do you mean? Could you, please, describe the desired behavior in all the possible details with live examples?
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.