0 votes

This search script works well. Thank you.

I would like to search for all scheduled tasks based on Activity Scope. I would like to delete all scheduled tasks that are configured to be assigned over a specific user.

image.png

What would be the best approach under this circumstance?

by (60 points)
edited by
0

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")
        }
    }
}

1 Answer

0 votes
by (294k points)

Hello,

Sorry for the confusion, but we are not quite sure what exactly you need to achieve and how it is related to question How can I use PowerShell code to get a list of scheduled task whose name match a partial search?. If custom command Dayforce terminate user now executes a PowerShell script and you need it to use properties of the target user, you can use value references. If that is not what you need, please, describe the desired workflow in all the possible details with live examples.

Related questions

0 votes
1 answer

Hi We have a set of business rules which are used for creating new distribution lists, these rules all have the same activity scope of a number of OUs, but the number of OUs ... when a new OU is created, it's not missed from the activity scope. Thanks Matt

asked May 12, 2022 by chappers77 (2.0k points)
0 votes
1 answer

I created a scheduled task (to export data) with a domain as its activity scope, runs perfectly. I modified it to use a Business Unit as its activity scope, now it ... the task effective for" should be checked, but the property is not editable in the dialog.

asked Mar 23, 2015 by sbanks (270 points)
0 votes
1 answer

Hi: I am trying to create a business rule that will stop a value change based on the existing value. For example, if the telephonenumber is 1234 for a group and has to ... the value it uses is the incoming value of the change, not the existing value. Thanks!

asked Jun 3, 2022 by crobitaille (80 points)
0 votes
1 answer

This is for license purposes and we do not want them visible in the Adaxes portal.

asked Oct 22, 2021 by jfrederickwl (20 points)
0 votes
0 answers

I'm brand new to this product and am still learning, I apologize for what are presumably bonehead questions. Here goes: 1) We've got a Create Contact action set up ... the custom form Exchange-enables the group? Thanks for the information, A brand new user.

asked Oct 4, 2016 by ctdhelpdesk (190 points)
3,588 questions
3,277 answers
8,303 comments
548,095 users