We have resolved the issue by cycling through each task in a container and checking the Activity Scope Items for the users DN. Thank you Serge for your assistance.
The following script has worked for us:
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$childContainer = "Scheduled Custom Commands" # the name of the container your scheduled tasks are stored in.
$userDN = "CN=Firstname Lastname,OU=Some Org,OU=Some Company,DC=yourdomain,DC=com"
# Get the scheduled task container path
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")
# Build ADS path to the scheduled tasks
$scheduledTasksPath = $service.Backend.GetConfigurationContainerPath("ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $scheduledTasksPath
$scheduledTaskPath = $scheduledTasksPathObj.CreateChildPath("CN=$childContainer")
# Bind to the scheduled tasks
$tasks = $service.OpenObject($scheduledTaskPath, $null, $null, 0)
foreach ($task in $tasks) {
# Get task name
$taskName = $task.Get("name")
# Check each activity scope item
foreach ($item in $task.ActivityScopeItems)
{
$baseObject = $item.BaseObject
if ($NULL -eq $baseObject)
{
continue
}
# Obtain the activity scope item DN and Full Name
$baseObjectDN = $baseObject.Get("distinguishedName")
$userFullName = $baseObject.Get("cn")
# If the items DN is eq to our user, then delete the scheduled task,..
if ($baseObjectDN -eq $userDN)
{
write-host("$userFullName is assigned over $taskName. Deleting the scheduled task")
$task.DeleteObject("ADM_DELETEOBJECTFLAGS_AUTO")
}
}
}