Script repository
The script returns true if the number of Microsoft 365 licenses is below limit. To execute the script, use the If PowerShell script returns true condition in a business rule, custom command or scheduled task.
Parameters
$limit- the minimum number of unused licenses. The script will return$trueif the number of available licenses is below this limit.$skus- the SKU Part Numbers of the licenses to check. If set to$null, the script checks all enabled licenses.
$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")
return
}
# 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))
{
continue
}
$difference = $sku.TotalUnits - $sku.ConsumedUnits
if ($difference -gt $limit)
{
continue
}
$Context.ConditionIsMet = $True
}
Comments 0
You must be signed in to comment.