Hello,
I have a scheduled task running daily at 1am. After that the Softerra.Adaxes.Service.exe process is using most of the available memory and brings the server to a crawl. The scheduled task calls a custom command, which in turn calls a script. The script is accessing Exchange Online, getting the user photo, and writing it to the on-prem AD thumbnailPhoto attribute. The task takes a little over an hour to run for about 75 users. I understand that it's currently over-writing the photo each night regardless of if a change occurred. Maybe there is a way to check if the two are identical and if so, skip? There are also some users that don't have a photo stored in Exchange Online, so it fails on that user but moves onto the next. Any thoughts on how to make this more efficient so it's not such a memory hog? Thanks!
try
{
# Connect to Exchange Online
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/?proxymethod=rps" `
-Credential $Context.GetOffice365Credential() -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue
Import-PSSession $session -AllowClobber -DisableNameChecking
$pictureBytes = Get-UserPhoto %userPrincipalName%
$Context.TargetObject.Put("thumbnailPhoto", $pictureBytes.PictureData)
$Context.TargetObject.SetInfo()
}
catch
{
$Context.LogMessage("The user doesn't have an Exchange Online Mailbox", "Warning")
return
}
finally
{
# Close the remote session and release resources
if ($session) { Remove-PSSession $session }
}