IAdmO365LicenseCondition

The IAdmO365LicenseCondition interface represents the If is licensed for Microsoft 365 condition.

Inheritance: IAdmCondition

Properties

  • Property

  • Description

  • ConditionType

  • Gets or sets a value indicating what is checked by the condition.

  • LogicalOperator

  • Gets or sets the logical operator that determines how to check Microsoft 365 services or licenses assigned to a user.

  • ServiceRequirements

  • Gets or sets a list of Microsoft 365 services that must be enabled or disabled to meet the condition.

Details

ConditionType

Gets or sets a value indicating what is checked by the condition. The condition can check whether at least one Microsoft 365 license is assigned to a user or whether specific Microsoft 365 services are enabled/disabled for a user.


LogicalOperator

Gets or sets the logical operator that determines how to check Microsoft 365 services or licenses assigned to a user.

  • Value

  • Condition is met

  • ADM_LOGICALOPERATION_AND

  • If the ConditionType property is set to ADM_O365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC, all the Microsoft 365 services listed in the ServiceRequirements property must be in the specified state.

    If the ConditionType property is set to ADM_O365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC, all the Microsoft 365 licenses listed in the IAdmO365LicenseCondition2::LicenseRequirements property must be in the specified state.

  • ADM_LOGICALOPERATION_OR

  • If the ConditionType property is set to ADM_O365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC, at least one Microsoft 365 service listed in the ServiceRequirements property must be in the specified state.

    If the ConditionType property is set to ADM_O365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC, at least one Microsoft 365 license listed in the IAdmO365LicenseCondition2::LicenseRequirements property must be in the specified state.


Remarks

The property is taken into account only if the ConditionType property is set to ADM_O365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC or ADM_O365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC.


ServiceRequirements

Gets or sets a list of Microsoft 365 services that must be enabled or disabled to meet the condition.

Remarks

The property is taken into account only if the ConditionType property is set to ADM_O365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC.

Examples

The following code sample creates a set of actions and conditions that cancels an operation if:

  • The Office Professional Plus service is enabled for a user.
  • The SharePoint Online (Plan 2) service is disabled for a user.
PowerShell
# The $obj variable refers to a business rule, custom command or scheduled task

# Create a new set of actions and conditions.
$actionsAndConditions = $obj.ConditionedActions.Create()
$actionsAndConditions.ConditionsLogicalOperation = `
    "ADM_LOGICALOPERATION_AND"
$actionsAndConditions.SetInfo()

#-----------------------------------------------------------------------
# If Office Professional Plus is enabled AND SharePoint Online (Plan 2) is disabled for the user
$condition = $actionsAndConditions.Conditions.CreateEx(
    "adm-O365LicenseCondition")
$microsoft365LicenseCondition = $condition.GetCondition()
$microsoft365LicenseCondition.ConditionType = "ADM_O365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC"
$serviceRequirements = $microsoft365LicenseCondition.ServiceRequirements
foreach ($requirement in $serviceRequirements)
{
    if ($requirement.Service.ServiceName -eq "OFFICESUBSCRIPTION")
    {
        $requirement.Enabled = $True
        $requirement.ServiceState = $True
    }
    elseif ($requirement.Service.ServiceName -eq "SHAREPOINTENTERPRISE")
    {
        $requirement.Enabled = $True
        $requirement.ServiceState = $False
    }
}
$microsoft365LicenseCondition.ServiceRequirements = $serviceRequirements
$condition.SetCondition($microsoft365LicenseCondition)
$condition.SetInfo()
$actionsAndConditions.Conditions.Add($condition)

#-----------------------------------------------------------------------
# Cancel the operation
$action = $actionsAndConditions.Actions.CreateEx(
    "adm-CancelOperationAction")
$action.ExecutionOptions = "ADM_ACTIONEXECUTIONOPTIONS_SYNC"
$cancelAction = $action.GetAction()
$cancelAction.ReasonMessage = "My Reason"
$action.SetAction($cancelAction)
$action.SetInfo()
$actionsAndConditions.Actions.Add($action)

# Add the set to the business rule, custom command or scheduled task.
$obj.ConditionedActions.Add($actionsAndConditions)
C#
// The obj variable refers to a business rule, custom command or scheduled task

// Create a new set of actions and conditions.
IAdmBusinessRuleConditionedActions actionsAndConditions =
    (IAdmBusinessRuleConditionedActions)obj.ConditionedActions.Create();
actionsAndConditions.ConditionsLogicalOperation =
    ADM_LOGICALOPERATION_ENUM.ADM_LOGICALOPERATION_AND;
actionsAndConditions.SetInfo();

////////////////////////////////////////////////////////////////////////
// If Office Professional Plus is enabled AND SharePoint Online (Plan 2) is disabled for the user
IAdmBusinessRuleCondition condition =
    (IAdmBusinessRuleCondition)actionsAndConditions.Conditions.CreateEx(
        "adm-O365LicenseCondition");
IAdmO365LicenseCondition microsoft365LicenseCondition =
    (IAdmO365LicenseCondition)condition.GetCondition();
microsoft365LicenseCondition.ConditionType =
    ADM_O365ACCOUNT_CONDITION_TYPE_ENUM.ADM_O365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC;
IAdmO365ServiceStateRequirement[] serviceRequirements =
    microsoft365LicenseCondition.ServiceRequirements;
foreach (IAdmO365ServiceStateRequirement requirement in serviceRequirements)
{
    if (requirement.Service.ServiceName == "OFFICESUBSCRIPTION")
    {
        requirement.Enabled = true;
        requirement.ServiceState = true;
    }
    else if (requirement.Service.ServiceName == "SHAREPOINTENTERPRISE")
    {
        requirement.Enabled = true;
        requirement.ServiceState = false;
    }
}
microsoft365LicenseCondition.ServiceRequirements = serviceRequirements;
condition.SetCondition(microsoft365LicenseCondition);
condition.SetInfo();
actionsAndConditions.Conditions.Add(condition);

////////////////////////////////////////////////////////////////////////
// Cancel the operation
IAdmBusinessRuleAction action =
    (IAdmBusinessRuleAction)actionsAndConditions.Actions.CreateEx(
        "adm-CancelOperationAction");
action.ExecutionOptions =
    ADM_ACTIONEXECUTIONOPTIONS_ENUM.ADM_ACTIONEXECUTIONOPTIONS_SYNC;
IAdmCancelOperationAction cancelAction =
    (IAdmCancelOperationAction)action.GetAction();
cancelAction.ReasonMessage = "My Reason";
action.SetAction(cancelAction);
action.SetInfo();
actionsAndConditions.Actions.Add(action);

// Add the set to the business rule, custom command or scheduled task.
obj.ConditionedActions.Add(actionsAndConditions);

Requirements

Minimum required version: 2014.1

See also