Skip to content

Replacing actions and conditions of a Custom Command

The following code sample replaces all actions and conditions of a Custom Command with new ones.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the Custom Command
$customCommandsPath = $admService.Backend.GetConfigurationContainerPath(
    "CustomCommands")
$customCommandsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $customCommandsPath
$myCustomCommandAdsPath = $customCommandsPathObj.CreateChildPath( `
    "CN=My Command")
$myCustomCommand = $admService.OpenObject($myCustomCommandAdsPath, $NULL, $NULL, 0)

# Delete old actions and conditions
$myCustomCommand.ConditionedActions.Clear()

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

# If account expired more than 30 days ago
$condition = $actionsAndConditions.Conditions.CreateEx(
    "adm-AccountPasswordExpirationCondition")
$expirationCondition = $condition.GetCondition()
$expirationCondition.ExpirationType = "ADM_EXPIRATIONTYPE_ACCOUNT"
$expirationCondition.ExpirationOperator =
    "ADM_EXPIRATIONOPERATOR_EXPIRED"
$expirationCondition.PeriodOperator =
    "ADM_EXPIRATIONCOMPARISONOPERATOR_MORETHAN"
$expirationCondition.PeriodValue = 30
$condition.SetCondition($expirationCondition)
$condition.SetInfo()
$actionsAndConditions.Conditions.Add($condition)

# Delete the object
$action = $actionsAndConditions.Actions.CreateEx(
    "adm-DeleteObjectAction")
$action.ExecutionOptions = "ADM_ACTIONEXECUTIONOPTIONS_SYNC"
$deleteAction = $action.GetAction()
$deleteAction.DeleteSubtree = $True
$action.SetAction($deleteAction)
$action.SetInfo()
$actionsAndConditions.Actions.Add($action)

# Add the set to the Custom Command
$myCustomCommand.ConditionedActions.Add($actionsAndConditions)

See also