Code 1
# The condition is met if $Context.ConditionIsMet is set to $True.
$Context.ConditionIsMet = $False
$threshold = 1000 # 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
Code 2
$serviceSettingsContainerPath = $Context.GetWellKnownContainerPath("ServiceSettings")
$serviceSettingsContainer = $Context.BindToObject($serviceSettingsContainerPath)
# Get number of users allowed by license
$productInfo = $serviceSettingsContainer.ProductInfo
$numberOfLicensedUsers = $productInfo.AllowedUserAccounts
# Get the number of enabled and not expired users
$numberOfEnabledAccounts = $productInfo.CalculateUserAccounts()
# Send email
$subject = "THIS IS A TEST Adaxes License Usage Alert THIS IS A TEST"
$bodytext = $Null
$body =
@"
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="x-apple-disable-message-reformatting">
<title></title>
<!--[if mso]>
<noscript>
<xml>
<o:OfficeDocumentSettings>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
</noscript>
<![endif]-->
<style>
table, td, div, h1, p {font-family: Arial, sans-serif;}
</style>
</head>
<body style="margin:0;padding:0;">
<table role="presentation" style="width:100%%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
<tr>
<td align="center" style="padding:0;">
<table role="presentation" style="width:602px;border-collapse:collapse;border:2px solid #f57e2c;border-spacing:0;text-align:left;">
<tr>
<td align="center" style="padding:40px 0 30px 0;background:#ffffff;border:2px solid #f57e2c;">
<img src="logo.jpg" alt="" width="300" style="height:auto;display:block;" /><p style="font-size:33px;margin:20px 0 0 0;font-family:Arial,sans-serif;"><strong>Adaxes License count is approching the maximum value</strong></p>
</td>
</tr>
<tr>
<td style="padding:36px 30px 42px 30px;">
<table role="presentation" style="width:100%%;border-collapse:collapse;border:0;border-spacing:0;">
<tr>
<td style="padding:0 0 0 0;color:#153643;">
<h1 style="font-size:20px;margin:0 0 20px 0;font-family:Arial,sans-serif;">Please do the following to fix the issue:</h1>
<p style="margin:0 0 0 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">- Reduce the amount of managed accounts</p>
<p style="margin:0 0 0 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">- Purchase additional licenses</p><nr/><br/>
<p style="margin:0 0 0 0;font-size:16px;line-height:24px;font-family:Arial,sans-serif;">Current License Usage: $numberOfEnabledAccounts / $numberOfLicensedUsers licenses in use.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding:30px;background:#f57e2c;">
<table role="presentation" style="width:100%%;border-collapse:collapse;border:0;border-spacing:0;font-size:9px;font-family:Arial,sans-serif;">
<tr>
<td style="padding:0;width:50%%;" align="center">
<p style="margin:0;font-size:20px;line-height:16px;font-family:Arial,sans-serif;color:#ffffff;"><strong>Adaxes Automated Emails</strong><br/>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
"@
$context.SendMail("[email redacted]", $Subject, $bodytext, $body)