dsccommunity / ComputerManagementDsc

DSC resources for for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings.
https://dsccommunity.org
MIT License
300 stars 83 forks source link

ScheduledTask: MultipleInstances Parameter Should Allow For 'StopExisting' #333

Closed Rob-S closed 4 years ago

Rob-S commented 4 years ago

Details of the scenario you tried and the problem that is occurring

In this case, we have a scheduled task that runs continuously but gets restarted daily, The manually created tasks specify "If the scheduled task is already running, then ... Stop the existing instance". This is one of four options in the drop-down box and shows up in the task's XML file as:

  <Settings>
    <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>

Verbose logs showing the problem

ComputerManagementDsc\ScheduledTask : At least one of the values 'StopExisting' is not supported or valid for property 'MultipleInstances' on class 'ScheduledTask'. Please specify only supported values: 
IgnoreNew, Parallel, Queue.
At C:\Git-Repositories\dba\dsc\sbcdb-sync\Compile-TaskSchedulerConfiguration.ps1:43 char:7
+       ScheduledTask 'MonitorTask'
+       ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnsupportedValueForProperty,ComputerManagementDsc\ScheduledTask

Suggested solution to the issue

Add "StopExisting" to the list of valid values for the MultipleInstances parameter.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

      ScheduledTask 'PSTask'
      {
         TaskName                         = 'pstask'
         TaskPath                         = '\'
         ActionExecutable                 = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
         ActionArguments                  = "-File `"C:\ps\myps.ps1`""
         ActionWorkingPath                = 'C:\ps'
         ScheduleType                     = 'Daily'
         RepeatInterval                   = '00:00:00'
         StartTime                        = '00:00:00.000' 
         SynchronizeAcrossTimeZone        = $false 
         Ensure                           = 'Present'
         Enable                           = $true
#         ExecuteAsCredential              = $ExecuteAs 
         DaysInterval                     = 1 
         RandomDelay                      = '00:00:00' 
         RepetitionDuration               = 'Indefinitely'
         WeeksInterval                    = 1 
         DisallowDemandStart              = $false
         DisallowHardTerminate            = $false
         AllowStartIfOnBatteries          = $true 
         Hidden                           = $false
         RunOnlyIfIdle                    = $false
         DisallowStartOnRemoteAppSession  = $false
         StartWhenAvailable               = $true
         DontStopIfGoingOnBatteries       = $true 
         WakeToRun                        = $true 
         RestartOnIdle                    = $false 
         DontStopOnIdleEnd                = $true
         ExecutionTimeLimit               = '00:00:00'
         MultipleInstances                = 'StopExisting'
         Priority                         = 0 
         RestartCount                     = 3 
         RestartInterval                  = '00:05:00'
         RunOnlyIfNetworkAvailable        = $false 
         RunLevel                         = 'Highest'
         LogonType                        = 'ServiceAccount'
      }

The operating system the target node is running

Version and build of PowerShell the target node is running

Version of the DSC module that was used ('dev' if using current dev branch)

ComputerManagementDsc 8.2.0

PlagueHO commented 4 years ago

Closing as addressed in #339