Script Repository


Check whether Microsoft 365 license is assigned to user

June 22, 2020
2622

The script can be used in Business Rules, Custom Commands and Scheduled Tasks to check whether a specific Microsoft 365 (Office 365) license is assigned to a user. To add it to your rule, command or task, use the If PowerShell script returns true condition. The script returns True if the license is assigned.

Parameter:

  • $licenseToCheck - specifies the SKU Part Number of the necessary license plan.
How 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
PowerShell
$licenseToCheck = "ENTERPRISEPACK" # TODO: modify me

$Context.ConditionIsMet = $False
try
{
    # Get Microsoft 365 account properties
    $microsoft365Properties = $Context.TargetObject.GetOffice365Properties()
}
catch
{
    return # No Microsoft 365 account
}

# Get assigned licenses
$licenses = $microsoft365Properties.Licenses

foreach ($license in $licenses)
{
    if (($license.Assigned) -and ($license.Sku.SkuPartNumber -eq $licenseToCheck))
    {
        $Context.ConditionIsMet = $True
        return
    }
}

Comments ( 0 )
No results found.
Leave a comment