How can I not allow Task Scheduler to execute a task out of its schedule?
I have a task which is scheduled daily at the night, and some times it is executed in the morning. The task is a powershell script (which I could prepend a short assert to exit if it is running out of its working hours, but I would like to understand Windows Task Scheduler)
Why Windows is running the task at 09:01 ?
Thank you!
PS C:\Windows\system32> Get-ScheduledTask "INTUNE41 - Apagar Equipo - 2024-02-12 093039" | select -ExpandProperty triggers
Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition : MSFT_TaskRepetitionPattern
StartBoundary : 2024-01-02T22:30:00+02:00
DaysInterval : 1
RandomDelay :
PSComputerName :
Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition : MSFT_TaskRepetitionPattern
StartBoundary : 2024-01-02T07:30:00+02:00
DaysInterval : 1
RandomDelay :
PSComputerName :
PS C:\Windows\system32> Get-ScheduledTask "INTUNE41 - Apagar Equipo - 2024-02-12 093039" | Get-ScheduledTaskInfo
LastRunTime : 30/04/2024 9:01:01
LastTaskResult : 0
NextRunTime : 30/04/2024 22:30:30
NumberOfMissedRuns : 0
TaskName : INTUNE41 - Apagar Equipo - 2024-02-12 093039
The task schedule was created with the next xml definition:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Author>.\Administrador</Author>
<URI>\apagar</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2024-01-02T22:30:00+02:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
<CalendarTrigger>
<StartBoundary>2024-01-02T07:30:00+02:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>true</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-executionpolicy bypass -file "c:\intune\Apagar Equipo\Aplicacion\Apagar Equipo.ps1"</Arguments>
</Exec>
</Actions>
</Task>