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 number of unused Microsoft 365 licenses is below limit

December 15, 2020 Views: 1252

The script returns true if the number of specific Microsoft 365 licenses in the tenant associated with the target object is below limit. You can use the script in the If PowerShell script returns true condition in Business Rules, Scheduled Tasks and Custom Commands.


  • $limit - Specifies the minimum number of unused licenses. The script will return TRUE if the number of available licenses is below this limit.
  • $skus - Specifies the SKU Part Numbers of the licenses to check. If set to NULL, the script will check all the enabled licenses.

    To get the SKU Part Number of a license plan in Adaxes:

    1. In Adaxes Administration Console, expand the service node that represents your Adaxes service.
    2. Navigate to Configuration\Cloud Services and select Microsoft 365.
    3. Double-click the Microsoft 365 (Office 365) tenant to which the license belongs.
    4. Click the necessary license plan. The SKU Part Number is displayed below the Display Name field.
Edit Remove
$limit = 5 # TODO: modify me
$skus = @("ENTERPRISEPREMIUM") # TODO: modify me

$Context.ConditionIsMet = $False
$tenantDN = "%adm-AssociatedO365Tenant%"
if ([System.String]::IsNullOrEmpty($tenantDN))
    $Context.LogMessage("No Microsoft 365 tenant is associated with the user", "Error")

# Bind to Microsoft 365 tenant
$tenant = $Context.BindToObjectByDN($tenantDN)

# Check licenses
foreach ($sku in $tenant.Skus)
    if (($skus -ne $NULL) -and ($skus -notcontains $sku.SkuPartNumber))
    $difference = $sku.TotalUnits - $sku.ConsumedUnits
    if ($difference -gt $limit)
    $Context.ConditionIsMet = $True
Comments 0
Leave a comment

Got questions?

Support Questions & Answers