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 (920 points)

1 Answer

0 votes
by (228k 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 (850 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 (530 points)
0 votes
1 answer

Currently, when I disable a user account in Adaxes, the group memberships of the user remain intact. I'd like to automate the removal of group memberships such as distribution ... a list of groups/DL that the user was previously in and removed from. Thanks!

asked Nov 3, 2021 by jayden.ang (20 points)
0 votes
1 answer

My scheduled task works like this (these are my action sets) Condition(s): Account is expired and home drive exists Action The user's home directory gets archived Condition(s): ... set? I do not want to split the scheduled task into two! Thanks in avance!

asked Apr 7 by lehnen (20 points)
0 votes
1 answer

Is there a way to have a Scheduled Task with 4 different condition? I want to create a scheduled task start every Monday and the condition see: The next Saturday of the week ... of the week is the fifth of the month then no action Thanks in advance, Simone

asked Jan 18 by Simone.Vailati (270 points)
2,807 questions
2,541 answers
6,615 comments
65,110 users