DSCResources/DSC_ScheduledTask/en-US/about_ScheduledTask.help.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
.NAME
    ScheduledTask
 
.DESCRIPTION
    The resource is used to define basic run once or recurring scheduled tasks
    on the local computer. It can also be used to delete or disable built-in
    scheduled tasks.
 
    ## Known Issues
 
    One of the values needed for the `MultipleInstances` parameter is missing from the
    `Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.MultipleInstancesEnum`
    enumerator. There are four valid values defined for the `MultipleInstances` property of the
    Task Settings ([TaskSettings.MultipleInstances Property](https://docs.microsoft.com/en-us/windows/win32/taskschd/tasksettings-multipleinstances "TaskSettings.MultipleInstances Property")).
    The `MultipleInstancesEnum` enumerator has three values, which can be mapped to three
    of the four valid values, but there is no value corresponding to `TASK_INSTANCES_STOP_EXISTING`.
    The result of this omission is that a workaround is required to
    accommodate the `StopExisting` value for the `MultipleInstances` parameter,
    which would not be necessary if the enumerator had all four valid values.
 
    ### ExecuteAsCredential
 
    #### When Using a BUILTIN Group
 
    When creating a scheduled task that uses an `ExecuteAsCredential` that
    is one of the 'BUILTIN' groups (e.g. 'BUILTIN\Users'), specifying the
    username to include the 'BUILTIN' domain name will result in the resource
    never going into state. The same behavior will also occur if setting a
    'BUILTIN' group in the UI.
 
    To prevent this issue, set the username in the `ExecuteAsCredential` to the
    name of the group only (e.g. 'Users').
 
    #### When Using a Domain User/Group
 
    When creating a scheduled task that uses an `ExecuteAsCredential` that
    is a domain user or group, (e.g. 'CONTOSO\ServiceUser'), the domain
    name must be included, otherwise the resource will not go into state.
 
    To prevent this issue, set the username in the `ExecuteAsCredential` to the
    name of the group only (e.g. 'CONTOSO\ServiceUser').
 
.PARAMETER TaskName
    Key - String
    The name of the task.
 
.PARAMETER TaskPath
    Write - String
    The path to the task - defaults to the root directory.
 
.PARAMETER Description
    Write - String
    The task description.
 
.PARAMETER ActionExecutable
    Write - String
    The path to the .exe for this task.
 
.PARAMETER ActionArguments
    Write - String
    The arguments to pass the executable.
 
.PARAMETER ActionWorkingPath
    Write - String
    The working path to specify for the executable.
 
.PARAMETER ScheduleType
    Write - String
    Allowed values: Once, Daily, Weekly, AtStartup, AtLogOn, OnEvent
    When should the task be executed.
 
.PARAMETER RepeatInterval
    Write - String
    How many units (minutes, hours, days) between each run of this task?
 
.PARAMETER StartTime
    Write - DateTime
    The time of day this task should start at - defaults to 12:00 AM. Not valid for AtLogon and AtStartup tasks.
 
.PARAMETER SynchronizeAcrossTimeZone
    Write - Boolean
    Enable the scheduled task option to synchronize across time zones. This is enabled by including the timezone offset in the scheduled task trigger. Defaults to false which does not include the timezone offset.
 
.PARAMETER Ensure
    Write - String
    Allowed values: Present, Absent
    Present if the task should exist, Absent if it should be removed.
 
.PARAMETER Enable
    Write - Boolean
    True if the task should be enabled, false if it should be disabled.
 
.PARAMETER BuiltInAccount
    Write - String
    Allowed values: SYSTEM, LOCAL SERVICE, NETWORK SERVICE
    Run the task as one of the built in service accounts. When set ExecuteAsCredential will be ignored and LogonType will be set to 'ServiceAccount'.
 
.PARAMETER ExecuteAsCredential
    Write - Instance
    The credential this task should execute as. If not specified defaults to running as the local system account.
 
.PARAMETER ExecuteAsGMSA
    Write - String
    The gMSA (Group Managed Service Account) this task should execute as. Cannot be used in combination with ExecuteAsCredential or BuiltInAccount.
 
.PARAMETER DaysInterval
    Write - UInt32
    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.
 
.PARAMETER RandomDelay
    Write - String
    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.
 
.PARAMETER RepetitionDuration
    Write - String
    Specifies how long the repetition pattern repeats after the task starts. May be set to `Indefinitely` to specify an indefinite duration.
 
.PARAMETER DaysOfWeek
    Write - StringArray
    Specifies an array of the days of the week on which Task Scheduler runs the task.
 
.PARAMETER WeeksInterval
    Write - UInt32
    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.
 
.PARAMETER User
    Write - String
    Specifies the identifier of the user for a trigger that starts a task when a user logs on.
 
.PARAMETER DisallowDemandStart
    Write - Boolean
    Indicates whether the task is prohibited to run on demand or not. Defaults to $false.
 
.PARAMETER DisallowHardTerminate
    Write - Boolean
    Indicates whether the task is prohibited to be terminated or not. Defaults to $false.
 
.PARAMETER Compatibility
    Write - String
    Allowed values: AT, V1, Vista, Win7, Win8
    The task compatibility level. Defaults to Vista.
 
.PARAMETER AllowStartIfOnBatteries
    Write - Boolean
    Indicates whether the task should start if the machine is on batteries or not. Defaults to $false.
 
.PARAMETER Hidden
    Write - Boolean
    Indicates that the task is hidden in the Task Scheduler UI.
 
.PARAMETER RunOnlyIfIdle
    Write - Boolean
    Indicates that Task Scheduler runs the task only when the computer is idle.
 
.PARAMETER IdleWaitTimeout
    Write - String
    Specifies the amount of time that Task Scheduler waits for an idle condition to occur.
 
.PARAMETER NetworkName
    Write - String
    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.
 
.PARAMETER DisallowStartOnRemoteAppSession
    Write - Boolean
    Indicates that the task does not start if the task is triggered to run in a Remote Applications Integrated Locally (RAIL) session.
 
.PARAMETER StartWhenAvailable
    Write - Boolean
    Indicates that Task Scheduler can start the task at any time after its scheduled time has passed.
 
.PARAMETER DontStopIfGoingOnBatteries
    Write - Boolean
    Indicates that the task does not stop if the computer switches to battery power.
 
.PARAMETER WakeToRun
    Write - Boolean
    Indicates that Task Scheduler wakes the computer before it runs the task.
 
.PARAMETER IdleDuration
    Write - String
    Specifies the amount of time that the computer must be in an idle state before Task Scheduler runs the task.
 
.PARAMETER RestartOnIdle
    Write - Boolean
    Indicates that Task Scheduler restarts the task when the computer cycles into an idle condition more than once.
 
.PARAMETER DontStopOnIdleEnd
    Write - Boolean
    Indicates that Task Scheduler does not terminate the task if the idle condition ends before the task is completed.
 
.PARAMETER ExecutionTimeLimit
    Write - String
    Specifies the amount of time that Task Scheduler is allowed to complete the task.
 
.PARAMETER MultipleInstances
    Write - String
    Allowed values: IgnoreNew, Parallel, Queue, StopExisting
    Specifies the policy that defines how Task Scheduler handles multiple instances of the task.
 
.PARAMETER Priority
    Write - UInt32
    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.
 
.PARAMETER RestartCount
    Write - UInt32
    Specifies the number of times that Task Scheduler attempts to restart the task.
 
.PARAMETER RestartInterval
    Write - String
    Specifies the amount of time that Task Scheduler attempts to restart the task.
 
.PARAMETER RunOnlyIfNetworkAvailable
    Write - Boolean
    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.
 
.PARAMETER RunLevel
    Write - String
    Allowed values: Limited, Highest
    Specifies the level of user rights that Task Scheduler uses to run the tasks that are associated with the principal. Defaults to 'Limited'.
 
.PARAMETER LogonType
    Write - String
    Allowed values: Group, Interactive, InteractiveOrPassword, None, Password, S4U, ServiceAccount
    Specifies the security logon method that Task Scheduler uses to run the tasks that are associated with the principal.
 
.PARAMETER EventSubscription
    Write - String
    Specifies the EventSubscription in XML. This can be easily generated using the Windows Eventlog Viewer. For the query schema please check: https://docs.microsoft.com/en-us/windows/desktop/WES/queryschema-schema. Can only be used in combination with ScheduleType OnEvent.
 
.PARAMETER Delay
    Write - String
    Specifies a delay to the start of the trigger. The delay is a static delay before the task is executed. Can only be used in combination with ScheduleType OnEvent.
 
.EXAMPLE 1
 
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. The task
execution will have no time limit.
 
Configuration ScheduledTask_CreateScheduledTaskOnce_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskOnceAdd
        {
            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'
            ExecutionTimeLimit = '00:00:00'
            ActionWorkingPath = (Get-Location).Path
            Enable = $true
            RandomDelay = '01:00:00'
            DisallowHardTerminate = $true
            RunOnlyIfIdle = $false
            Priority = 9
        }
    }
}
 
.EXAMPLE 2
 
This example creates a scheduled task called 'Test task interactive' in the folder
task folder 'MyTasks' that starts a new powershell process once. The task will
execute using the credential passed into the $Credential parameter, but only when
the user contained in the $Credential is logged on.
 
Configuration ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config
{
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        $Credential
    )
 
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask MaintenanceScriptExample
        {
            TaskName = 'Test task Interactive'
            TaskPath = '\MyTasks'
            ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ScheduleType = 'Once'
            ActionWorkingPath = (Get-Location).Path
            Enable = $true
            ExecuteAsCredential = $Credential
            LogonType = 'Interactive'
        }
    }
}
 
.EXAMPLE 3
 
This example disables the built-in scheduled task called
'CreateExplorerShellUnelevatedTask'.
 
Configuration ScheduledTask_DisableABuiltInTask_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask DisableCreateExplorerShellUnelevatedTask
        {
            TaskName = 'CreateExplorerShellUnelevatedTask'
            TaskPath = '\'
            Enable = $false
        }
    }
}
 
.EXAMPLE 4
 
This example deletes the built-in scheduled task called
'CreateExplorerShellUnelevatedTask'.
 
Configuration ScheduledTask_DeleteABuiltInTask_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask DeleteCreateExplorerShellUnelevatedTask
        {
            TaskName = 'CreateExplorerShellUnelevatedTask'
            TaskPath = '\'
            Ensure = 'Absent'
        }
    }
}
 
.EXAMPLE 5
 
This example creates a scheduled task called 'TriggerOnServiceFailures' in the folder
root folder. The task is delayed by exactly 30 seconds each time. The task will run when
an error event 7001 of source Service Control Manager is generated in the system log.
When a service crashes, it waits for 30 seconds and then starts a new PowerShell instance,
in which the file c:\temp\seeme.txt get's created with the value 'Worked!'
 
Configuration ScheduledTask_CreateScheduledTasksOnEvent_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ServiceEventManager
        {
            TaskName = 'TriggerOnServiceFailures'
            Ensure = 'Present'
            ScheduleType = 'OnEvent'
            ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ActionArguments = '-Command Set-Content -Path c:\temp\seeme.txt -Value ''Worked!'''
            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>'
            Delay = '00:00:30'
        }
    }
}
 
.EXAMPLE 6
 
This example creates a scheduled task called 'Test task Run As gMSA'
in the folder task folder 'MyTasks' that starts a new powershell process once.
The task will run as the user passed into the ExecuteAsGMSA parameter.
 
Configuration ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config
{
    param
    (
        # Group Managed Service Account must be in the form of DOMAIN\gMSA$ or user@domain.fqdn (UPN)
        [Parameter()]
        [ValidatePattern('^\w+\\\w+\$$|\w+@\w+\.\w+')]
        [System.String]
        $GroupManagedServiceAccount = 'DOMAIN\gMSA$'
    )
 
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask MaintenanceScriptExample
        {
            TaskName = 'Test task Run As gMSA'
            TaskPath = '\MyTasks'
            ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ScheduleType = 'Once'
            ActionWorkingPath = (Get-Location).Path
            Enable = $true
            ExecuteAsGMSA = $GroupManagedServiceAccount
        }
    }
}
 
.EXAMPLE 7
 
This example creates a scheduled task called 'Test task sync across time zone enabled'
in the folder 'MyTasks' that starts a new powershell process once 2018-10-01 01:00
The task will have the option Synchronize across time zone enabled.
 
Configuration ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled
        {
            TaskName = 'Test task sync across time zone enabled'
            TaskPath = '\MyTasks\'
            ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ScheduleType = 'Once'
            StartTime = '2018-10-01T01:00:00'
            SynchronizeAcrossTimeZone = $true
            ActionWorkingPath = (Get-Location).Path
            Enable = $true
        }
    }
}
 
.EXAMPLE 8
 
This example creates a scheduled task called 'Test As NetworkService' in
the folder root folder. The task is set to run every 15 minutes.
When run the task will start a new PowerShell instance running as the
builtin user NETWORK SERVICE.
The PowerShell instance will write the value of $env:USERNAME to the
file c:\temp\seeme.txt.
The contents of c:\temp\seeme.txt should be "NETWORK SERVICE".
 
Configuration ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskAsNetworkService
        {
            TaskName = 'Test As NetworkService'
            Ensure = 'Present'
            ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ActionArguments = '-Command Set-Content -Path c:\temp\seeme.txt -Value $env:USERNAME -Force'
            ScheduleType = 'Once'
            RepeatInterval = '00:15:00'
            RepetitionDuration = '4.00:00:00'
            BuiltInAccount = 'NETWORK SERVICE'
        }
    }
}
 
 
.EXAMPLE 9
 
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 ScheduledTask_CreateScheduledTaskDaily_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskDailyAdd
        {
            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
        }
    }
}
 
.EXAMPLE 10
 
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 ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskDailyIndefinitelyAdd
        {
            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'
        }
    }
}
 
.EXAMPLE 11
 
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 ScheduledTask_CreateScheduledTasksWeekly_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskWeeklyAdd
        {
            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
        }
    }
}
 
.EXAMPLE 12
 
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 ScheduledTask_CreateScheduledTasksAtLogon_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskLogonAdd
        {
            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'
        }
    }
}
 
.EXAMPLE 13
 
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 ScheduledTask_CreateScheduledTasksAtStartup_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask ScheduledTaskStartupAdd
        {
            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'
        }
    }
}
 
.EXAMPLE 14
 
This example will create a scheduled task that will call PowerShell.exe every 15
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 ScheduledTask_RunPowerShellTaskEvery15Minutes_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask 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 = '4.00:00:00'
        }
    }
}
 
.EXAMPLE 15
 
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 ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config
{
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask 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'
        }
    }
}
 
.EXAMPLE 16
 
This example creates a scheduled task called 'Test task Run As Highest Privilege'
in the folder task folder 'MyTasks' that starts a new powershell process once.
The task will run as the credential passed into the $Credential parameter, running
with the highest privileges.
 
Configuration ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config
{
    param
    (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        $Credential
    )
 
    Import-DscResource -ModuleName ComputerManagementDsc
 
    Node localhost
    {
        ScheduledTask MaintenanceScriptExample
        {
            TaskName = 'Test task Run As Highest Privilege'
            TaskPath = '\MyTasks'
            ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ScheduleType = 'Once'
            ActionWorkingPath = (Get-Location).Path
            Enable = $true
            ExecuteAsCredential = $Credential
            RunLevel = 'Highest'
        }
    }
}