Script Repository


Check whether Office 365 license is assigned to user

June 30, 2017
1515

The script can be used in Business Rules, Custom Commands and Scheduled Tasks to check whether a specific Office365 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 \ Office 365.
  3. Double-click the 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 Office 365 account properties
    $office365Properties = $Context.TargetObject.GetOffice365Properties()
}
catch
{
    return # No Office 365 account
}

# Get assigned licenses
$licenses = $office365Properties.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