Hello -
I'm working on my companies off boarding process and need to run a Custom Command that turns off access to different systems and resources at the time specified. I've been using the code examples on the site to create a scheduled task via PowerShell but I'm stuck on the part where I need to have the action run a custom command for a specific user.
I'm getting the user that should have the work done and I have the custom command GUID, but I'm not sure how to feed that into the Scheduled Task's actions. Any help would be great!
Thanks!
[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 'Scheduled Tasks' container
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath(
"ScheduledTasks")
$scheduledTasksContainer = $admService.OpenObject($scheduledTasksPath,
$NULL, $NULL, 0)
# Create a new Scheduled Task
$task = $scheduledTasksContainer.Create("adm-ScheduledTask", "CN=Disable %fullname%")
$task.ObjectType = "user"
$task.Description = "Process Off-boarding for %fullname%"
$task.Disabled = $False
$task.ExecutionMoment = "ADM_BUSINESSRULEEXECMOMENT_BEFORE"
$task.OperationType = "none"
# Specify the schedule for the task
$recurrencePattern = $task.GetRecurrencePattern()
$recurrencePattern.RecurrenceType = "ADM_RECURRENCEPATTERNTYPE_ONCE"
$recurrencePattern.PatternStartDateTime = %adm-CustomAttributeDate3%
$task.SetRecurrencePattern($recurrencePattern)
$task.DeleteTaskAfterExecution = $True #Delete after run is turned on
#Define actions and conditions for the task
$actionAndConditions = $task.ConditionedActions.Create()
$action = $actionAndConditions.Actions.CreateEx("adm-OffBoarduser")
$action.ExecutionOptions = "ADM_ACTIONEXECUTIONOPTIONS_SYNC"
$removeAction = $action.GetAction()
$removeAction
#Getting the user object
$userDN = %distinguishedName%
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)
#Getting the Custom Command
$commandID = "{9db88ec3-1241-4ab1-9612-c7c982baa49f}"
$user.ExecuteCustomCommand($commandID)
# Save the Scheduled Task
$task.SetInfo()