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 (70 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 (300k 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

Hello I am trying to build a report. This report should have any user in it that has a True for adm-customboolean12. I am trying this script for testing: [Reflection.Assembly]:: ... } I have a test user set up in the OU but the searcher never finds them.

asked Mar 5 by mightycabal (1.1k points)
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
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)
0 votes
1 answer

We have 3 email domains. 1 primary and 2 subsidary companies. I'm needing to automate setting the email domain during user creation based on department. See attached ... to be able to automate this for ongoing maintenance if users move between departments.

asked Mar 7 by browndervilleb (20 points)
3,667 questions
3,352 answers
8,468 comments
549,173 users