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
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")
# Bind to the custom command
$customCommandsPath = $service.Backend.GetConfigurationContainerPath(
"CustomCommands")
$customCommandsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
$customCommandsPath
$myCustomCommandAdsPath = $customCommandsPathObj.CreateChildPath( `
"CN=My Command")
$myCustomCommand = $service.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
- Managing custom commands
- Binding to Adaxes-specific objects
- Managing Adaxes-specific objects
- IAdmCustomCommand
- IAdmCollection
- Online script repository