We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Check if Adaxes license is close to violation

November 27, 2024 Views: 3414

The script calculates the difference between the current number of enabled and not expired user accounts and that allowed by Adaxes license. If the difference is less than the specified threshold, the script returns true. It should be executed in the If PowerShell script returns true condition in a business rule, custom command or scheduled task.


In the script, the $threshold variable specifies the threshold that should not be exceeded for the condition to be met.

Edit Remove
PowerShell
$threshold = 100 # TODO: modify me

$serviceSettingsContainerPath = $Context.GetWellKnownContainerPath("ServiceSettings")
$serviceSettingsContainer = $Context.BindToObject($serviceSettingsContainerPath)

# Get number of users allowed by license
$productInfo = $serviceSettingsContainer.ProductInfo
$numberOfLicensedUsers = $productInfo.AllowedUserAccounts

if (($numberOfLicensedUsers -eq -2) -or ($numberOfLicensedUsers -eq -1))
{
    # Adaxes service is still calculating the number of enabled and not expired
    # users or the license is unlimited
    $Context.ConditionIsMet = $False
    return
}

# Get the number of enabled and not expired users
$numberOfEnabledAccounts = $productInfo.CalculateUserAccounts()

$Context.ConditionIsMet = ($numberOfLicensedUsers - $numberOfEnabledAccounts) -lt $threshold
Comments 2
avatar
Wojciech Tauroginski Apr 22, 2025
when i use it in scheduled task it sends me mulltiple emails but when i try to run it in powershell This script returns error:
You cannot call a method on a null-valued expression.
At line:3 char:1
+ $serviceSettingsContainerPath = $Context.GetWellKnownContainerPath("S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:4 char:1
+ $serviceSettingsContainer = $Context.BindToObject($serviceSettingsCon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:19 char:1
+ $numberOfEnabledAccounts = $productInfo.CalculateUserAccounts()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

The property 'ConditionIsMet' cannot be found on this object. Verify that the property exists and can be set.
At line:21 char:1
+ $Context.ConditionIsMet = ($numberOfLicensedUsers - $numberOfEnabledA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
avatar
Support Apr 22, 2025
Hello Wojciech,

>when i use it in scheduled task it sends me mulltiple emails

It is expected in case you have multiple objects in the Activity Scope of the scheduled task. In this case, there must be only one object. For example, you can have a scheduled task configured for the Domain object type and add a single domain to the Activity Scope.

>when i try to run it in powershell This script returns error

The script only works in the If PowerShell script returns true condition in a business rule, custom command or scheduled task. If you attempt to execute the script in Windows PowerShell or in the Run a program or PowerShell script action, it is expected to fail.
avatar
Wojciech Tauroginski Apr 30, 2025
Great i set it assigned over i service account user and not it works like a charm. Thank You
Leave a comment
Loading...

Got questions?

Support Questions & Answers