0 votes

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 }
}

by (4.9k points)

1 Answer

0 votes
by (182k points)
selected by
Best answer

Hello,

It is a known issue when using the Import-PSSession in PowerShell 3.0 and higher. As a solution, we recommend adding the If PowerShell script returns true condition to your Custom Command that will check whether the user has a mailbox in Exchange Online and update your script accordingly. In the condition, you need to use the following script from our repository: https://www.adaxes.com/script-repositor ... e-s303.htm.

In the action of the Custom Command, the following script should be used:

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 -CommandName "Get-UserPhoto"

    $pictureBytes = Get-UserPhoto %userPrincipalName%

    $Context.TargetObject.Put("thumbnailPhoto", $pictureBytes.PictureData)
    $Context.TargetObject.SetInfo()
}
finally
{
    # Close the remote session and release resources
    if ($session) { Remove-PSSession $session }
}

Finally, the Custom Command will look like the following:

0

Thanks! I'll give that a try.

Related questions

0 votes
1 answer

Dear Adaxes support, can you please advise if there an option to release memory, used by Adaxes service? I'm facing an issue with 2019.1 that after ... ) $computer.SetInfo() } } } Remove-Module $ConfigMgrModulePath -ErrorAction SilentlyContinue Thanks, Dmytro

asked Jun 25, 2019 by Dmytro.Rudyi (4.1k points)
0 votes
1 answer

Since upgrading to 2018.2 we are experiencing an issue where the Softerra.Adaxes.Service will consume all of the OS's available memory causing it to become unresponsive. ... for the service or figure out what might be causing the high memory utilization?

asked Nov 2, 2018 by yourpp (2.5k points)
0 votes
1 answer

I am trying to send a $context.logmessage from a condition script in a Scheduled Task but I get nothing in the log. Is this not possible? Morten A. Steien

asked Jul 20 by Morten A. Steien (280 points)
0 votes
0 answers

I am creating a new scheduled task and form. We would like to have the ability to schedule the reassignment of a staff member to a different location in the future. ... context, my manager won't necessarily know when he tries to move somebody. Thanks everybody

asked May 21 by jcalvert (650 points)
0 votes
1 answer

Hi, I need to start Adaxes scheduled task from Powershell console running on another host. How can I do that?

asked May 21 by KIT (2.9k points)
2,247 questions
2,007 answers
5,495 comments
20,768 users