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