Skip to content

Commit b27136c

Browse files
committed
Adding example for OnEvent scheduled task configuration and adding help to parameters
1 parent 08c1f32 commit b27136c

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

Modules/ComputerManagementDsc/DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.psm1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ $script:localizedData = Get-LocalizedData `
201201
.PARAMETER LogonType
202202
Specifies the security logon method that Task Scheduler uses to run the tasks that
203203
are associated with the principal. Not used in Get-TargetResource.
204+
205+
.PARAMETER EventSubscription
206+
The event subscription in a string that can be parsed as valid XML. This parameter is only
207+
valid in combination with the OnEvent Schedule Type.
208+
209+
.PARAMETER Delay
210+
The time to wait after an event based trigger was triggered. This parameter is only
211+
valid in combination with the OnEvent Schedule Type.
204212
#>
205213
function Get-TargetResource
206214
{
@@ -681,6 +689,14 @@ function Get-TargetResource
681689
.PARAMETER LogonType
682690
Specifies the security logon method that Task Scheduler uses to run the tasks that
683691
are associated with the principal.
692+
693+
.PARAMETER EventSubscription
694+
The event subscription in a string that can be parsed as valid XML. This parameter is only
695+
valid in combination with the OnEvent Schedule Type.
696+
697+
.PARAMETER Delay
698+
The time to wait after an event based trigger was triggered. This parameter is only
699+
valid in combination with the OnEvent Schedule Type.
684700
#>
685701
function Set-TargetResource
686702
{
@@ -1436,6 +1452,14 @@ function Set-TargetResource
14361452
.PARAMETER LogonType
14371453
Specifies the security logon method that Task Scheduler uses to run the tasks that
14381454
are associated with the principal.
1455+
1456+
.PARAMETER EventSubscription
1457+
The event subscription in a string that can be parsed as valid XML. This parameter is only
1458+
valid in combination with the OnEvent Schedule Type.
1459+
1460+
.PARAMETER Delay
1461+
The time to wait after an event based trigger was triggered. This parameter is only
1462+
valid in combination with the OnEvent Schedule Type.
14391463
#>
14401464
function Test-TargetResource
14411465
{

Modules/ComputerManagementDsc/DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.schema.mof

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MSFT_ScheduledTask : OMI_BaseResource
77
[Write, Description("The path to the .exe for this task")] string ActionExecutable;
88
[Write, Description("The arguments to pass the executable")] string ActionArguments;
99
[Write, Description("The working path to specify for the executable")] string ActionWorkingPath;
10-
[Write, Description("When should the task be executed"), ValueMap{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn"}, Values{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn"}] string ScheduleType;
10+
[Write, Description("When should the task be executed"), ValueMap{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn", "OnEvent"}, Values{"Once", "Daily", "Weekly", "AtStartup", "AtLogOn", "OnEvent"}] string ScheduleType;
1111
[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;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<#
2+
.EXAMPLE
3+
This example creates a scheduled task called 'TriggerOnServiceFailures' in the folder
4+
root folder. The task is delayed by exactly 30 seconds each time. The task will run when
5+
an error event 7001 of source Service Control Manager is generated in the system log.
6+
When a service crashes, it waits for 30 seconds and then starts a new PowerShell instance,
7+
in which the command Invoke-ServiceCrashReport will be executed.
8+
#>
9+
Configuration Example
10+
{
11+
param
12+
(
13+
[Parameter()]
14+
[System.String[]]
15+
$NodeName = 'localhost'
16+
)
17+
18+
Import-DscResource -ModuleName ComputerManagementDsc
19+
20+
Node $NodeName
21+
{
22+
ScheduledTask ServiceEventManager
23+
{
24+
TaskName = 'TriggerOnServiceFailures'
25+
Ensure = 'Present'
26+
ScheduleType = 'OnEvent'
27+
ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
28+
ActionArguments = '-Command Invoke-ServiceCrashReport'
29+
EventSubscription = '<QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name=''Service Control Manager''] and (Level=2) and (EventID=7001)]]</Select></Query></QueryList>'
30+
Delay = '00:00:30'
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)