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 (292k 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

Similar to Powershell's "whatif"? I'd like to enable this scheduled task - But would like to confirm who will actually be affected before enabling this. Is there at least ... objects in the console log? I could run that before adding the 'modify' actions back.

asked Jun 25 by msinger (210 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 (240 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)
3,569 questions
3,259 answers
8,275 comments
547,987 users