Skip to content

Commit 4b2d74d

Browse files
authored
Squash Issue 85 (#1)
* BREAKING CHANGE- Converted all xScheduledTask Interval/Duration type parameters over to be string format * Fix parameter mismatch * Change AppVeyor Environment * Fixed xScheduledTask Integration tests to run on older OS * Improve test coverage * BREAKING CHANGE- Converted all xScheduledTask Interval/Duration type parameters over to be string format * Fix parameter mismatch * Change AppVeyor Environment * Fixed xScheduledTask Integration tests to run on older OS * Improve test coverage * Added support for setting repetition duration to Indefinitely. * BREAKING CHANGE- Converted all xScheduledTask Interval/Duration type parameters over to be string format Fix parameter mismatch Change AppVeyor Environment Fixed xScheduledTask Integration tests to run on older OS Improve test coverage BREAKING CHANGE- Converted all xScheduledTask Interval/Duration type parameters over to be string format Fix parameter mismatch Change AppVeyor Environment Fixed xScheduledTask Integration tests to run on older OS Improve test coverage * Added support for setting repetition duration to Indefinitely. * Correct examples * Fix up tests * Added more verbose message to try and identify problem in V4 * Fix problems in creating triggers * Rewriting trigger repetition code * Another fix for WS2012 * Add some info to help debug test failures * More changes for testing * Another attempt at fixing WS2012R2 * One more try * Final fix up of Scheduled Task * Final tweaks
1 parent 645e4b4 commit 4b2d74d

10 files changed

Lines changed: 1662 additions & 861 deletions

DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.psm1

Lines changed: 751 additions & 554 deletions
Large diffs are not rendered by default.

DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.schema.mof

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ class MSFT_xScheduledTask : OMI_BaseResource
88
[Write, Description("The arguments to pass the executable")] string ActionArguments;
99
[Write, Description("The working path to specify for the executable")] string ActionWorkingPath;
1010
[Required, Description("When should the task be executed"), ValueMap{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn"}, Values{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn"}] string ScheduleType;
11-
[Write, Description("How many units (minutes, hours, days) between each run of this task?")] DateTime RepeatInterval;
11+
[Write, Description("How many units (minutes, hours, days) between each run of this task?")] String RepeatInterval;
1212
[Write, Description("The time of day this task should start at - defaults to 12:00 AM. Not valid for AtLogon and AtStartup tasks")] DateTime StartTime;
1313
[Write, Description("Present if the task should exist, Absent if it should be removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
1414
[Write, Description("True if the task should be enabled, false if it should be disabled")] boolean Enable;
1515
[Write, Description("The credential this task should execute as. If not specified defaults to running as the local system account"), EmbeddedInstance("MSFT_Credential")] string ExecuteAsCredential;
1616
[Write, Description("Specifies the interval between the days in the schedule. An interval of 1 produces a daily schedule. An interval of 2 produces an every-other day schedule.")] Uint32 DaysInterval;
17-
[Write, Description("Specifies a random amount of time to delay the start time of the trigger. The delay time is a random time between the time the task triggers and the time that you specify in this setting.")] DateTime RandomDelay;
18-
[Write, Description("Specifies how long the repetition pattern repeats after the task starts.")] DateTime RepetitionDuration;
17+
[Write, Description("Specifies a random amount of time to delay the start time of the trigger. The delay time is a random time between the time the task triggers and the time that you specify in this setting.")] String RandomDelay;
18+
[Write, Description("Specifies how long the repetition pattern repeats after the task starts. May be set to `Indefinitely` to specify an indefinite duration.")] String RepetitionDuration;
1919
[Write, Description("Specifies an array of the days of the week on which Task Scheduler runs the task.")] String DaysOfWeek[];
2020
[Write, Description("Specifies the interval between the weeks in the schedule. An interval of 1 produces a weekly schedule. An interval of 2 produces an every-other week schedule.")] Uint32 WeeksInterval;
2121
[Write, Description("Specifies the identifier of the user for a trigger that starts a task when a user logs on.")] String User;
@@ -25,19 +25,19 @@ class MSFT_xScheduledTask : OMI_BaseResource
2525
[Write, Description("Indicates whether the task should start if the machine is on batteries or not. Defaults to $false")] Boolean AllowStartIfOnBatteries;
2626
[Write, Description("Indicates that the task is hidden in the Task Scheduler UI.")] Boolean Hidden;
2727
[Write, Description("Indicates that Task Scheduler runs the task only when the computer is idle.")] Boolean RunOnlyIfIdle;
28-
[Write, Description("Specifies the amount of time that Task Scheduler waits for an idle condition to occur.")] DateTime IdleWaitTimeout;
28+
[Write, Description("Specifies the amount of time that Task Scheduler waits for an idle condition to occur.")] String IdleWaitTimeout;
2929
[Write, Description("Specifies the name of a network profile that Task Scheduler uses to determine if the task can run. The Task Scheduler UI uses this setting for display purposes. Specify a network name if you specify the RunOnlyIfNetworkAvailable parameter.")] String NetworkName;
3030
[Write, Description("Indicates that the task does not start if the task is triggered to run in a Remote Applications Integrated Locally (RAIL) session.")] Boolean DisallowStartOnRemoteAppSession;
3131
[Write, Description("Indicates that Task Scheduler can start the task at any time after its scheduled time has passed.")] Boolean StartWhenAvailable;
3232
[Write, Description("Indicates that the task does not stop if the computer switches to battery power.")] Boolean DontStopIfGoingOnBatteries;
3333
[Write, Description("Indicates that Task Scheduler wakes the computer before it runs the task.")] Boolean WakeToRun;
34-
[Write, Description("Specifies the amount of time that the computer must be in an idle state before Task Scheduler runs the task.")] DateTime IdleDuration;
34+
[Write, Description("Specifies the amount of time that the computer must be in an idle state before Task Scheduler runs the task.")] String IdleDuration;
3535
[Write, Description("Indicates that Task Scheduler restarts the task when the computer cycles into an idle condition more than once.")] Boolean RestartOnIdle;
3636
[Write, Description("Indicates that Task Scheduler does not terminate the task if the idle condition ends before the task is completed.")] Boolean DontStopOnIdleEnd;
37-
[Write, Description("Specifies the amount of time that Task Scheduler is allowed to complete the task.")] DateTime ExecutionTimeLimit;
37+
[Write, Description("Specifies the amount of time that Task Scheduler is allowed to complete the task.")] String ExecutionTimeLimit;
3838
[Write, Description("Specifies the policy that defines how Task Scheduler handles multiple instances of the task."), ValueMap{"IgnoreNew","Parallel","Queue"}, Values{"IgnoreNew","Parallel","Queue"}] String MultipleInstances;
3939
[Write, Description("Specifies the priority level of the task. Priority must be an integer from 0 (highest priority) to 10 (lowest priority). The default value is 7. Priority levels 7 and 8 are used for background tasks. Priority levels 4, 5, and 6 are used for interactive tasks.")] Uint32 Priority;
4040
[Write, Description("Specifies the number of times that Task Scheduler attempts to restart the task.")] Uint32 RestartCount;
41-
[Write, Description("Specifies the amount of time that Task Scheduler attempts to restart the task.")] DateTime RestartInterval;
41+
[Write, Description("Specifies the amount of time that Task Scheduler attempts to restart the task.")] String RestartInterval;
4242
[Write, Description("Indicates that Task Scheduler runs the task only when a network is available. Task Scheduler uses the NetworkID parameter and NetworkName parameter that you specify in this cmdlet to determine if the network is available.")] Boolean RunOnlyIfNetworkAvailable;
4343
};

Examples/xScheduledTask/1-CreateScheduledTasks.ps1

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This example creates five tasks with the following schedules that start a new powershell process
44
- Once at 00:00 repeating every 15 minutes for 8 hours
55
- Daily at 00:00 repeating every 15 minutes for 8 hours
6+
- Daily at 00:00 repeating every 15 minutes indefinitely
67
- Weekly at 00:00 repeating every 15 minutes for 8 hours on Mon, Wed, Sat
78
- At logon repeating every 15 minutes for 8 hours
89
- At startup repeating every 15 minutes for 8 hours
@@ -26,11 +27,11 @@ Configuration Example
2627
TaskPath = '\MyTasks'
2728
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
2829
ScheduleType = 'Once'
29-
RepeatInterval = [datetime]::Today.AddMinutes(15)
30-
RepetitionDuration = [datetime]::Today.AddHours(8)
30+
RepeatInterval = '00:15:00'
31+
RepetitionDuration = '08:00:00'
3132
ActionWorkingPath = (Get-Location).Path
3233
Enable = $true
33-
RandomDelay = [datetime]::Today.AddMinutes(60)
34+
RandomDelay = '01:00:00'
3435
DisallowHardTerminate = $true
3536
RunOnlyIfIdle = $false
3637
Priority = 9
@@ -43,10 +44,25 @@ Configuration Example
4344
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
4445
ScheduleType = 'Daily'
4546
DaysInterval = 1
46-
RepeatInterval = [datetime]::Today.AddMinutes(15)
47-
RepetitionDuration = [datetime]::Today.AddHours(8)
47+
RepeatInterval = '00:15:00'
48+
RepetitionDuration = '08:00:00'
4849
RestartCount = 2
49-
RestartInterval = [datetime]::Today.AddMinutes(5)
50+
RestartInterval = '00:05:00'
51+
RunOnlyIfNetworkAvailable = $true
52+
WakeToRun = $true
53+
}
54+
55+
xScheduledTask xScheduledTaskDailyIndefinitelyAdd
56+
{
57+
TaskName = 'Test task Daily Indefinitely'
58+
TaskPath = '\MyTasks'
59+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
60+
ScheduleType = 'Daily'
61+
DaysInterval = 1
62+
RepeatInterval = '00:15:00'
63+
RepetitionDuration = 'Indefinitely'
64+
RestartCount = 2
65+
RestartInterval = '00:05:00'
5066
RunOnlyIfNetworkAvailable = $true
5167
WakeToRun = $true
5268
}
@@ -59,8 +75,8 @@ Configuration Example
5975
ScheduleType = 'Weekly'
6076
WeeksInterval = 1
6177
DaysOfWeek = 'Monday','Wednesday','Saturday'
62-
RepeatInterval = [datetime]::Today.AddMinutes(15)
63-
RepetitionDuration = [datetime]::Today.AddHours(8)
78+
RepeatInterval = '00:15:00'
79+
RepetitionDuration = '08:00:00'
6480
AllowStartIfOnBatteries = $true
6581
Compatibility = 'Win8'
6682
Hidden = $true
@@ -72,18 +88,18 @@ Configuration Example
7288
TaskPath = '\MyTasks'
7389
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
7490
ScheduleType = 'AtLogOn'
75-
RepeatInterval = [datetime]::Today.AddMinutes(15)
76-
RepetitionDuration = [datetime]::Today.AddHours(8)
91+
RepeatInterval = '08:00:00'
92+
RepetitionDuration = '08:00:00'
7793
}
78-
94+
7995
xScheduledTask xScheduledTaskStartupAdd
8096
{
8197
TaskName = 'Test task Startup'
8298
TaskPath = '\MyTasks'
8399
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
84100
ScheduleType = 'AtStartup'
85-
RepeatInterval = [datetime]::Today.AddMinutes(15)
86-
RepetitionDuration = [datetime]::Today.AddHours(8)
101+
RepeatInterval = '08:00:00'
102+
RepetitionDuration = '08:00:00'
87103
}
88104
}
89105
}

Examples/xScheduledTask/2-RunPowerShellTaskEvery15Minutes.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<#
22
.EXAMPLE
33
This example will create a scheduled task that will call PowerShell.exe every 15
4-
minutes to run a script saved locally.
5-
The script will be called as the local system account
4+
minutes for 4 days to run a script saved locally.
5+
The script will be called as the local system account.
66
#>
77
Configuration Example
88
{
@@ -23,8 +23,8 @@ Configuration Example
2323
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
2424
ActionArguments = "-File `"C:\scripts\my custom script.ps1`""
2525
ScheduleType = 'Once'
26-
RepeatInterval = [datetime]::Today.AddMinutes(15)
27-
RepetitionDuration = [datetime]::Today.AddHours(10)
26+
RepeatInterval = '00:15:00'
27+
RepetitionDuration = '4.00:00:00'
2828
}
2929
}
3030
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<#
2+
.EXAMPLE
3+
This example will create a scheduled task that will call PowerShell.exe every 15
4+
minutes indefinitely to run a script saved locally.
5+
The script will be called as the local system account.
6+
#>
7+
Configuration Example
8+
{
9+
param
10+
(
11+
[Parameter()]
12+
[System.String[]]
13+
$NodeName = 'localhost'
14+
)
15+
16+
Import-DscResource -ModuleName xComputerManagement
17+
18+
Node $NodeName
19+
{
20+
xScheduledTask MaintenanceScriptExample
21+
{
22+
TaskName = "Custom maintenance tasks"
23+
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
24+
ActionArguments = "-File `"C:\scripts\my custom script.ps1`""
25+
ScheduleType = 'Once'
26+
RepeatInterval = '00:15:00'
27+
RepetitionDuration = 'Indefinitely'
28+
}
29+
}
30+
}

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ resource that can only be used once in a configuration and has following propert
8080

8181
xScheduledTask resource is used to define basic recurring scheduled tasks on the
8282
local computer.
83-
Tasks are created to run indefinitely based on the schedule defined.
83+
Tasks are created to run based on the schedule defined.
8484
xScheduledTask has the following properties:
8585

8686
* TaskName: The name of the task
@@ -108,7 +108,7 @@ xScheduledTask has the following properties:
108108
trigger. The delay time is a random time between the time the task triggers
109109
and the time that you specify in this setting.
110110
* RepetitionDuration: Specifies how long the repetition pattern repeats after
111-
the task starts.
111+
the task starts. May be set to `Indefinitely` to specify an indefinite duration.
112112
* DaysOfWeek: Specifies an array of the days of the week on which Task Scheduler
113113
runs the task.
114114
* WeeksInterval: Specifies the interval between the weeks in the schedule. An
@@ -167,8 +167,9 @@ xScheduledTask has the following properties:
167167

168168
### xScheduledTask Examples
169169

170-
* [Create five different scheduled tasks that run PowerShell](/Examples/xScheduledTask/1-CreateScheduledTasks.ps1)
171-
* [Run a PowerShell script every 15 minutes on a server](/Examples/xScheduledTask/2-RunPowerShellTaskEvery15Minutes.ps1)
170+
* [Create six different scheduled tasks that run PowerShell](/Examples/xScheduledTask/1-CreateScheduledTasks.ps1)
171+
* [Run a PowerShell script every 15 minutes for 4 days on a server](/Examples/xScheduledTask/2-RunPowerShellTaskEvery15Minutes.ps1)
172+
* [Run a PowerShell script every 15 minutes Indefinitely on a server](/Examples/xScheduledTask/3-3-RunPowerShellTaskEvery15MinutesIndefinitely.ps1)
172173

173174
## xPowerPlan
174175

@@ -206,6 +207,14 @@ xVirtualMemory has the following properties:
206207

207208
* xComputer: Added parameter to set the local computer description along with documentation
208209
and unit tests for this change.
210+
* BREAKING CHANGE: xScheduledTask:
211+
* Converted all Interval/Duration type parameters over to be string format
212+
to prevent the Timezone the MOF file was created in from being stored.
213+
This is to fix problems where MOF files are created in one timezone but
214+
deployed nodes to a different timezone - See [Issue #85](https://github.com/PowerShell/xComputerManagement/issues/85)
215+
* Added ConvertTo-TimeSpanFromScheduledTaskString function and refactored
216+
to reduce code duplication.
217+
* Added support for setting repetition duration to `Indefinitely`.
209218

210219
### 2.1.0.0
211220

0 commit comments

Comments
 (0)