IAdmM365LicenseCondition

The IAdmM365LicenseCondition 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.

  • LicenseRequirements

  • Gets or sets requirements to the state of Microsoft 365 licenses that should be satisfied to meet the condition.

  • 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_M365ACCOUNT_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_M365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC, all the Microsoft 365 licenses listed in the IAdmM365LicenseCondition::LicenseRequirements property must be in the specified state.

  • ADM_LOGICALOPERATION_OR

  • If the ConditionType property is set to ADM_M365ACCOUNT_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_M365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC, at least one Microsoft 365 license listed in the IAdmM365LicenseCondition::LicenseRequirements property must be in the specified state.

Remarks

The property is taken into account only if the ConditionType property is set to ADM_M365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC or ADM_M365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC.


LicenseRequirements

Gets or sets requirements to the state of Microsoft 365 licenses that should be satisfied to meet the condition.

Remarks

The property is taken into account only if the IAdmM365LicenseCondition::ConditionType property is set to ADM_M365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC.

Examples

The following code sample creates an action set that cancels an operation if Microsoft 365 license ENTERPRISEPACK is assigned.

Powershell
# The $obj variable refers to a business rule, custom command or scheduled task.

# Create a new action set.
$actionsAndConditions = $obj.ConditionedActions.Create()
$actionsAndConditions.ConditionsLogicalOperation = "ADM_LOGICALOPERATION_AND"
$actionsAndConditions.SetInfo()

#-----------------------------------------------------------------------
# If ENTERPRISEPACK license is assigned
$condition = $actionsAndConditions.Conditions.CreateEx("adm-O365LicenseCondition")
$licenseCondition = $condition.GetCondition()
$licenseCondition.ConditionType = "ADM_M365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC"
$licenseRequirements = $licenseCondition.LicenseRequirements
foreach ($requirement in $licenseRequirements)
{
    $license = $requirement.License
    if ($license.Sku.SkuPartNumber -eq "ENTERPRISEPACK")
    {
        $requirement.Enabled = $true
        $requirement.LicenseState = $true
        break
    }    
}
$licenseCondition.LicenseRequirements = $licenseRequirements
$condition.SetCondition($licenseCondition)
$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 action set.
IAdmBusinessRuleConditionedActions actionsAndConditions =
    (IAdmBusinessRuleConditionedActions)obj.ConditionedActions.Create();
actionsAndConditions.ConditionsLogicalOperation =
    ADM_LOGICALOPERATION_ENUM.ADM_LOGICALOPERATION_AND;
actionsAndConditions.SetInfo();

////////////////////////////////////////////////////////////////////////
// If ENTERPRISEPACK license is assigned
IAdmBusinessRuleCondition condition =
    (IAdmBusinessRuleCondition)actionsAndConditions.Conditions.CreateEx(
        "adm-O365LicenseCondition");
IAdmM365LicenseCondition licenseCondition =
    (IAdmM365LicenseCondition)condition.GetCondition();
licenseCondition.ConditionType =
    ADM_M365ACCOUNT_CONDITION_TYPE_ENUM.ADM_M365ACCOUNT_CONDITION_TYPE_LICENSESPECIFIC;
IAdmM365LicenseStateRequirement[] licenseRequirements =
    licenseCondition.LicenseRequirements;
foreach (IAdmM365LicenseStateRequirement requirement in licenseRequirements)
{
    IAdmM365License license = (IAdmM365License) requirement.License;
    if (license.Sku.SkuPartNumbe == "ENTERPRISEPACK")
    {
        requirement.Enabled = true;
        requirement.LicenseState = true;
    }
}
licenseCondition.LicenseRequirements = licenseRequirements;
condition.SetCondition(licenseCondition);
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);

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_M365ACCOUNT_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_M365ACCOUNT_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");
IAdmM365LicenseCondition microsoft365LicenseCondition =
    (IAdmM365LicenseCondition)condition.GetCondition();
microsoft365LicenseCondition.ConditionType =
    ADM_M365ACCOUNT_CONDITION_TYPE_ENUM.ADM_M365ACCOUNT_CONDITION_TYPE_SERVICESPECIFIC;
IAdmM365ServiceStateRequirement[] serviceRequirements =
    microsoft365LicenseCondition.ServiceRequirements;
foreach (IAdmM365ServiceStateRequirement 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: 2023

See also