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 (190k 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 have a scheduled task that runs a PowerShell script. The script checks various properties of each user, and uses $Context.LogMessage to report on properties that are not ... (doesn't have to be LogMessage) into a single report or single notification email?

asked Oct 13, 2020 by jcrook (250 points)
0 votes
1 answer

We are using Adaxes to manage multiple domains. upwards of 10 domains. There is no trust between the domains. The are all separate stand alone. We want to setup a scheduled ... domain has an Adaxes service account setup and that is what i would want to use.

asked Sep 14, 2020 by gt_111 (250 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, 2020 by Morten A. Steien (280 points)
2,375 questions
2,131 answers
5,763 comments
180,568 users