Skip to content

Commit

Permalink
Merge pull request #100 from PlagueHO/dev
Browse files Browse the repository at this point in the history
BREAKING CHANGE: xScheduledTask Duration/Interval Fields Changed to Strings - Fixes #85
  • Loading branch information
PlagueHO authored Sep 19, 2017
2 parents 645e4b4 + e1ba5ff commit f42dfd1
Show file tree
Hide file tree
Showing 16 changed files with 1,935 additions and 993 deletions.
1,384 changes: 791 additions & 593 deletions DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.psm1

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class MSFT_xScheduledTask : OMI_BaseResource
[Write, Description("The arguments to pass the executable")] string ActionArguments;
[Write, Description("The working path to specify for the executable")] string ActionWorkingPath;
[Required, Description("When should the task be executed"), ValueMap{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn"}, Values{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn"}] string ScheduleType;
[Write, Description("How many units (minutes, hours, days) between each run of this task?")] DateTime RepeatInterval;
[Write, Description("How many units (minutes, hours, days) between each run of this task?")] String RepeatInterval;
[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;
[Write, Description("Present if the task should exist, Absent if it should be removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
[Write, Description("True if the task should be enabled, false if it should be disabled")] boolean Enable;
[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;
[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;
[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;
[Write, Description("Specifies how long the repetition pattern repeats after the task starts.")] DateTime RepetitionDuration;
[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;
[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;
[Write, Description("Specifies an array of the days of the week on which Task Scheduler runs the task.")] String DaysOfWeek[];
[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;
[Write, Description("Specifies the identifier of the user for a trigger that starts a task when a user logs on.")] String User;
Expand All @@ -25,19 +25,19 @@ class MSFT_xScheduledTask : OMI_BaseResource
[Write, Description("Indicates whether the task should start if the machine is on batteries or not. Defaults to $false")] Boolean AllowStartIfOnBatteries;
[Write, Description("Indicates that the task is hidden in the Task Scheduler UI.")] Boolean Hidden;
[Write, Description("Indicates that Task Scheduler runs the task only when the computer is idle.")] Boolean RunOnlyIfIdle;
[Write, Description("Specifies the amount of time that Task Scheduler waits for an idle condition to occur.")] DateTime IdleWaitTimeout;
[Write, Description("Specifies the amount of time that Task Scheduler waits for an idle condition to occur.")] String IdleWaitTimeout;
[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;
[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;
[Write, Description("Indicates that Task Scheduler can start the task at any time after its scheduled time has passed.")] Boolean StartWhenAvailable;
[Write, Description("Indicates that the task does not stop if the computer switches to battery power.")] Boolean DontStopIfGoingOnBatteries;
[Write, Description("Indicates that Task Scheduler wakes the computer before it runs the task.")] Boolean WakeToRun;
[Write, Description("Specifies the amount of time that the computer must be in an idle state before Task Scheduler runs the task.")] DateTime IdleDuration;
[Write, Description("Specifies the amount of time that the computer must be in an idle state before Task Scheduler runs the task.")] String IdleDuration;
[Write, Description("Indicates that Task Scheduler restarts the task when the computer cycles into an idle condition more than once.")] Boolean RestartOnIdle;
[Write, Description("Indicates that Task Scheduler does not terminate the task if the idle condition ends before the task is completed.")] Boolean DontStopOnIdleEnd;
[Write, Description("Specifies the amount of time that Task Scheduler is allowed to complete the task.")] DateTime ExecutionTimeLimit;
[Write, Description("Specifies the amount of time that Task Scheduler is allowed to complete the task.")] String ExecutionTimeLimit;
[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;
[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;
[Write, Description("Specifies the number of times that Task Scheduler attempts to restart the task.")] Uint32 RestartCount;
[Write, Description("Specifies the amount of time that Task Scheduler attempts to restart the task.")] DateTime RestartInterval;
[Write, Description("Specifies the amount of time that Task Scheduler attempts to restart the task.")] String RestartInterval;
[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;
};
38 changes: 38 additions & 0 deletions Examples/xScheduledTask/1-CreateScheduledTaskOnce.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<#
.EXAMPLE
This example creates a scheduled task called 'Test task Once' in the folder
task folder 'MyTasks' that starts a new powershell process once at 00:00 repeating
every 15 minutes for 8 hours. The task is delayed by a random amount up to 1 hour
each time. The task will run even if the previous task is still running and it
will prevent hard termintaing of the previously running task instance.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask xScheduledTaskOnceAdd
{
TaskName = 'Test task Once'
TaskPath = '\MyTasks'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ScheduleType = 'Once'
RepeatInterval = '00:15:00'
RepetitionDuration = '08:00:00'
ActionWorkingPath = (Get-Location).Path
Enable = $true
RandomDelay = '01:00:00'
DisallowHardTerminate = $true
RunOnlyIfIdle = $false
Priority = 9
}
}
}
89 changes: 0 additions & 89 deletions Examples/xScheduledTask/1-CreateScheduledTasks.ps1

This file was deleted.

37 changes: 37 additions & 0 deletions Examples/xScheduledTask/2-CreateScheduledTaskDaily.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<#
.EXAMPLE
This example creates a scheduled task called 'Test task Daily' in the folder
task folder 'MyTasks' that starts a new powershell process every day at 00:00 repeating
every 15 minutes for 8 hours. If the task fails it will be restarted after 5 minutes
and it will be restarted a maximum of two times. It will only run if the network
is connected and will wake the machine up to execute the task.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask xScheduledTaskDailyAdd
{
TaskName = 'Test task Daily'
TaskPath = '\MyTasks'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ScheduleType = 'Daily'
DaysInterval = 1
RepeatInterval = '00:15:00'
RepetitionDuration = '08:00:00'
RestartCount = 2
RestartInterval = '00:05:00'
RunOnlyIfNetworkAvailable = $true
WakeToRun = $true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#
.EXAMPLE
This example creates a scheduled task called 'Test task Daily Indefinitely' in the folder
task folder 'MyTasks' that starts a new powershell process every day at 00:00 repeating
every 15 minutes indefinitely.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask xScheduledTaskDailyIndefinitelyAdd
{
TaskName = 'Test task Daily Indefinitely'
TaskPath = '\MyTasks'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ScheduleType = 'Daily'
DaysInterval = 1
RepeatInterval = '00:15:00'
RepetitionDuration = 'Indefinitely'
}
}
}
37 changes: 37 additions & 0 deletions Examples/xScheduledTask/4-CreateScheduledTasksWeekly.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<#
.EXAMPLE
This example creates a scheduled task called 'Test task Weekly' in the folder
task folder 'MyTasks' that starts a new powershell process every week on
Monday, Wednesday and Saturday at 00:00 repeating every 15 minutes for 8 hours.
The task will be hidden and will be allowed to start if the machine is running
on batteries. The task will be compatible with Windows 8.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask xScheduledTaskWeeklyAdd
{
TaskName = 'Test task Weekly'
TaskPath = '\MyTasks'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ScheduleType = 'Weekly'
WeeksInterval = 1
DaysOfWeek = 'Monday','Wednesday','Saturday'
RepeatInterval = '00:15:00'
RepetitionDuration = '08:00:00'
AllowStartIfOnBatteries = $true
Compatibility = 'Win8'
Hidden = $true
}
}
}
30 changes: 30 additions & 0 deletions Examples/xScheduledTask/5-CreateScheduledTasksAtLogon.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<#
.EXAMPLE
This example creates a scheduled task called 'Test task Logon' in the folder
task folder 'MyTasks' that starts a new powershell process when the machine
is logged on repeating every 15 minutes for 8 hours.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask xScheduledTaskLogonAdd
{
TaskName = 'Test task Logon'
TaskPath = '\MyTasks'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ScheduleType = 'AtLogOn'
RepeatInterval = '00:15:00'
RepetitionDuration = '08:00:00'
}
}
}
31 changes: 31 additions & 0 deletions Examples/xScheduledTask/6-CreateScheduledTasksAtStartup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#
.EXAMPLE
This example creates a scheduled task called 'Test task Startup' in the folder
task folder 'MyTasks' that starts a new powershell process when the machine
is started up repeating every 15 minutes for 8 hours.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask xScheduledTaskStartupAdd
{
TaskName = 'Test task Startup'
TaskPath = '\MyTasks'
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
ScheduleType = 'AtStartup'
RepeatInterval = '00:15:00'
RepetitionDuration = '08:00:00'
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<#
.EXAMPLE
This example will create a scheduled task that will call PowerShell.exe every 15
minutes to run a script saved locally.
The script will be called as the local system account
minutes for 4 days to run a script saved locally. The task will start immediately.
The script will be called as the local system account.
#>
Configuration Example
{
Expand All @@ -23,8 +23,8 @@ Configuration Example
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
ActionArguments = "-File `"C:\scripts\my custom script.ps1`""
ScheduleType = 'Once'
RepeatInterval = [datetime]::Today.AddMinutes(15)
RepetitionDuration = [datetime]::Today.AddHours(10)
RepeatInterval = '00:15:00'
RepetitionDuration = '4.00:00:00'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<#
.EXAMPLE
This example will create a scheduled task that will call PowerShell.exe every 15
minutes indefinitely to run a script saved locally. The task will start immediately.
The script will be called as the local system account.
#>
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)

Import-DscResource -ModuleName xComputerManagement

Node $NodeName
{
xScheduledTask MaintenanceScriptExample
{
TaskName = "Custom maintenance tasks"
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
ActionArguments = "-File `"C:\scripts\my custom script.ps1`""
ScheduleType = 'Once'
RepeatInterval = '00:15:00'
RepetitionDuration = 'Indefinitely'
}
}
}
Loading

0 comments on commit f42dfd1

Please sign in to comment.