Script Repository


Check Microsoft 365 license being assigned

February 25, 2021
1189

The script can be used in a business rule triggering Before modifying Microsoft 365 properties of a user to check whether a specific Microsoft 365 (Office 365) license is being assigned to a user. To execute the script, use the If PowerShell script returns true condition. It will return True if the license is being assigned.

Parameter:

  • $licenseToCheck - Specifies the SKU Part Number of the Microsoft 365 (Office 365) license to check.
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

# Get Microsoft 365 properties
$microsoft365Properties = New-Object Softerra.Adaxes.Adsi.CloudServices.Office365.AdmO365AccountProperties
$microsoft365Properties.LoadFromPropertyList($Context.Action.PropertyList)

# Check license
$Context.ConditionIsMet = $False
foreach ($license in $microsoft365Properties.Licenses)
{
    if (($license.Assigned) -and ($license.Sku.SkuPartNumber -eq $licenseToCheck))
    {
        $Context.ConditionIsMet = $True
        return
    }
}

Comments ( 7 )
avatar
ComputerHabit
Sep 08, 2020
Doesn't work. "$Context.Action.PropertyList" is empty.
avatar
Support
Sep 09, 2020

Hello,

What exactly is not working? Do you face any error messages? If so, please, provide us with screenshots. Also, please, provide us with the exact script you are using (with all your modifications) and a screenshot of the Business Rule executing the script.

avatar
Matt Chapman
Aug 19, 2021
Hi

I'm trying to use this but get 2 errors:
Exception calling "LoadFromPropertyList" with "1" argument(s): "Value cannot be null. Parameter name: propertyList" Stack trace: at <ScriptBlock>, <No file>: line 5
The property 'ConditionIsMet' cannot be found on this object. Verify that the property exists and can be set. Stack trace: at <ScriptBlock>, <No file>: line 8
avatar
Support
Aug 20, 2021
Hello Matt,

According to the error message, you are using the script in Run a program or PowerShell script action, not in the If PowerShell script returns true condition. It will not work as the script is specifically dedicated for the condition only.
avatar
Matt Chapman
Aug 20, 2021
Ahhh, got it. Thanks.
avatar
Kristoffer Johansson
Nov 18, 2021
How can this script be modified to return whether the user already has a license, or one of multiple licenses assigned?
I want to check if an account has the necessary licenses (enterprisepack,enterprisepremum,exchangeenterprise) to it before doing a modification on it. So a powershell return true or false seems like a good option.
avatar
Support
Nov 18, 2021
Hello Kristoffer,

In the latest version of Adaxes, there is no need to use scripts to check Microsoft 365 licenses already assigned to a user. It can be done using the If is licensed for Microsoft 365 condition.

If you are using Adaxes 2020.1 or older, you can use the below script. For information on how to check the version of Adaxes you are currently using, have a look at the following help article: https://www.adaxes.com/help/CheckServiceVersion.

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
    }
}
avatar
Kristoffer Again...
Nov 18, 2021
I actually realized you already had a condition for that. It is called Is licenced in Office 365 and there I could select the licenses.
Great solution, keep up the good work!
Leave a comment

Related Scripts