Skip to content

Commit 0449e71

Browse files
committed
Changes as per PR comments
1 parent 4b2d74d commit 0449e71

12 files changed

Lines changed: 432 additions & 307 deletions

DSCResources/MSFT_xScheduledTask/MSFT_xScheduledTask.psm1

Lines changed: 105 additions & 104 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'Test task Once' in the folder
4+
task folder 'MyTasks' that starts a new powershell process once at 00:00 repeating
5+
every 15 minutes for 8 hours. The task is delayed by a random amount up to 1 hour
6+
each time. The task will run even if the previous task is still running and it
7+
will prevent hard termintaing of the previously running task instance.
8+
#>
9+
Configuration Example
10+
{
11+
param
12+
(
13+
[Parameter()]
14+
[System.String[]]
15+
$NodeName = 'localhost'
16+
)
17+
18+
Import-DscResource -ModuleName xComputerManagement
19+
20+
Node $NodeName
21+
{
22+
xScheduledTask xScheduledTaskOnceAdd
23+
{
24+
TaskName = 'Test task Once'
25+
TaskPath = '\MyTasks'
26+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
27+
ScheduleType = 'Once'
28+
RepeatInterval = '00:15:00'
29+
RepetitionDuration = '08:00:00'
30+
ActionWorkingPath = (Get-Location).Path
31+
Enable = $true
32+
RandomDelay = '01:00:00'
33+
DisallowHardTerminate = $true
34+
RunOnlyIfIdle = $false
35+
Priority = 9
36+
}
37+
}
38+
}

Examples/xScheduledTask/1-CreateScheduledTasks.ps1

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'Test task Daily' in the folder
4+
task folder 'MyTasks' that starts a new powershell process every day at 00:00 repeating
5+
every 15 minutes for 8 hours. If the task fails it will be restarted after 5 minutes
6+
and it will be restarted a maximum of two times. It will only run if the network
7+
is connected and will wake the machine up to execute the task.
8+
#>
9+
Configuration Example
10+
{
11+
param
12+
(
13+
[Parameter()]
14+
[System.String[]]
15+
$NodeName = 'localhost'
16+
)
17+
18+
Import-DscResource -ModuleName xComputerManagement
19+
20+
Node $NodeName
21+
{
22+
xScheduledTask xScheduledTaskDailyAdd
23+
{
24+
TaskName = 'Test task Daily'
25+
TaskPath = '\MyTasks'
26+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
27+
ScheduleType = 'Daily'
28+
DaysInterval = 1
29+
RepeatInterval = '00:15:00'
30+
RepetitionDuration = '08:00:00'
31+
RestartCount = 2
32+
RestartInterval = '00:05:00'
33+
RunOnlyIfNetworkAvailable = $true
34+
WakeToRun = $true
35+
}
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'Test task Daily Indefinitely' in the folder
4+
task folder 'MyTasks' that starts a new powershell process every day at 00:00 repeating
5+
every 15 minutes indefinitely.
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 xScheduledTaskDailyIndefinitelyAdd
21+
{
22+
TaskName = 'Test task Daily Indefinitely'
23+
TaskPath = '\MyTasks'
24+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
25+
ScheduleType = 'Daily'
26+
DaysInterval = 1
27+
RepeatInterval = '00:15:00'
28+
RepetitionDuration = 'Indefinitely'
29+
}
30+
}
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'Test task Weekly' in the folder
4+
task folder 'MyTasks' that starts a new powershell process every week on
5+
Mon, Wed, Sat at 00:00 repeating every 15 minutes for 8 hours. The task will
6+
be hidden and will be allowed to start if the machine is running on batteries.
7+
The task will be compatible with Windows 8.
8+
#>
9+
Configuration Example
10+
{
11+
param
12+
(
13+
[Parameter()]
14+
[System.String[]]
15+
$NodeName = 'localhost'
16+
)
17+
18+
Import-DscResource -ModuleName xComputerManagement
19+
20+
Node $NodeName
21+
{
22+
xScheduledTask xScheduledTaskWeeklyAdd
23+
{
24+
TaskName = 'Test task Weekly'
25+
TaskPath = '\MyTasks'
26+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
27+
ScheduleType = 'Weekly'
28+
WeeksInterval = 1
29+
DaysOfWeek = 'Monday','Wednesday','Saturday'
30+
RepeatInterval = '00:15:00'
31+
RepetitionDuration = '08:00:00'
32+
AllowStartIfOnBatteries = $true
33+
Compatibility = 'Win8'
34+
Hidden = $true
35+
}
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'Test task Logon' in the folder
4+
task folder 'MyTasks' that starts a new powershell process when the machine
5+
is logged on repeating every 15 minutes for 8 hours.
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 xScheduledTaskLogonAdd
21+
{
22+
TaskName = 'Test task Logon'
23+
TaskPath = '\MyTasks'
24+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
25+
ScheduleType = 'AtLogOn'
26+
RepeatInterval = '00:15:00'
27+
RepetitionDuration = '08:00:00'
28+
}
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'Test task Startup' in the folder
4+
task folder 'MyTasks' that starts a new powershell process when the machine
5+
is started up repeating every 15 minutes for 8 hours.
6+
7+
#>
8+
Configuration Example
9+
{
10+
param
11+
(
12+
[Parameter()]
13+
[System.String[]]
14+
$NodeName = 'localhost'
15+
)
16+
17+
Import-DscResource -ModuleName xComputerManagement
18+
19+
Node $NodeName
20+
{
21+
xScheduledTask xScheduledTaskStartupAdd
22+
{
23+
TaskName = 'Test task Startup'
24+
TaskPath = '\MyTasks'
25+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
26+
ScheduleType = 'AtStartup'
27+
RepeatInterval = '00:15:00'
28+
RepetitionDuration = '08:00:00'
29+
}
30+
}
31+
}

Examples/xScheduledTask/2-RunPowerShellTaskEvery15Minutes.ps1 renamed to Examples/xScheduledTask/7-RunPowerShellTaskEvery15Minutes.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#
22
.EXAMPLE
33
This example will create a scheduled task that will call PowerShell.exe every 15
4-
minutes for 4 days to run a script saved locally.
4+
minutes for 4 days to run a script saved locally. The task will start immediately.
55
The script will be called as the local system account.
66
#>
77
Configuration Example

Examples/xScheduledTask/3-RunPowerShellTaskEvery15MinutesIndefinitely.ps1 renamed to Examples/xScheduledTask/8-RunPowerShellTaskEvery15MinutesIndefinitely.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#
22
.EXAMPLE
33
This example will create a scheduled task that will call PowerShell.exe every 15
4-
minutes indefinitely to run a script saved locally.
4+
minutes indefinitely to run a script saved locally. The task will start immediately.
55
The script will be called as the local system account.
66
#>
77
Configuration Example

0 commit comments

Comments
 (0)