Skip to content

IAdmO365LicenseCondition

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

Inheritance: The IAdmO365LicenseCondition interface inherits from the IAdmCondition interface.

Properties

  • Property

  • Description

  • ConditionType

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

  • LogicalOperator

  • Gets or sets a logical operator that determines how to check Microsoft 365 services 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 a logical operator that determines how to check Microsoft 365 services assigned to a user. If AND, all Microsoft 365 services listed in the ServiceRequirements property, must be in the same state (enabled or disabled) as specified in it. If OR, at least one of the Microsoft 365 services listed in the ServiceRequirements 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.


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.
# 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)
// 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