0 votes

Is there a way to have a Scheduled Task with 4 different condition? I want to create a scheduled task start every Monday and the condition see:

The next Saturday of the week is the first of the month then take a action The next Saturday of the week is the second of the month then take a different action The next Saturday of the week is the thirt of the month then take a different action The next Saturday of the week is the fourth of the month then take a different action The next Saturday of the week is the fifth of the month then no action

Thanks in advance, Simone

by (430 points)

1 Answer

0 votes
by (267k points)
selected by
Best answer

Hello Simone,

Yes, it is possible. You will need to use a scheduled task executed every Monday. In the task conditions, use the below script to determine whether the next Saturday matches the specified number. In the script, the $requiredNumber variable specifies the number that should be matched.

$requiredNumber = 3 # TODO: modify me

$date = (Get-Date).AddDays(-5)
$weekdayCalc = [int][Math]::Floor($date.Day / 7)
$weekdayNum = if ($date.Day %% 7 -eq 0) {$weekdayCalc} else {$weekdayCalc+1}

$Context.ConditionIsMet = $requiredNumber -eq $weekdayNum

Finally, the scheduled task will look like the following: image.png

Related questions

0 votes
1 answer

seting up a scheduled task to move users to thier correct OU. For some we can do this based on employee type and direct to a specific OU. For most of our users we will have to script this to move to the manager's OU.

asked Apr 12, 2023 by mightycabal (1.0k points)
0 votes
1 answer

When I enable a scheduled task, instead of running at the scheduled time they all run imeadiately. This is not good behavior as changes are written in a way to reflect the ... is being enabled. I am hoping there is a powershell command to stop this behavoir.

asked Jul 10, 2023 by mightycabal (1.0k points)
0 votes
1 answer

We have four OUs in Active Directory (Pending Deletion, Disabled with Mail Delegates, Disabled with HR Extensions and Disabled_Temp_Leave) that users are moved to prior to their eventual ... past 7 days have been moved to one of 4 of these OUs. Thanks!

asked Jun 3, 2021 by RayBilyk (230 points)
0 votes
1 answer

For example, if the scope is a specified OU, running the report will list management history for every object in the OU even if it has had no management operations ... so objects that have not had any recent modifications are excluded from the report results?

asked Aug 13, 2021 by ryan741 (120 points)
0 votes
1 answer

I am wanting to export a list of users including the properties of a specific custom attribute. Ideally, I would be able to run a get-admuser and filter on a custom attribute, but even an excel report with the custom attributes would work. Is this possible?

asked Sep 9, 2021 by ggallaway (300 points)
3,293 questions
2,991 answers
7,664 comments
544,192 users