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