Skip to content

Commit

Permalink
Issue-dsccommunity#333 Workaround for Get-ScheduledTask bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-S committed Jun 17, 2020
1 parent 2972d8c commit a3f5a28
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,17 @@ function Get-CurrentResource
$PrincipalId = 'UserId'
}

<# The following workaround is needed because Get-StartedTask currently returns NULL for the value
of $settings.MultipleInstances when the started task is set to "Stop the existing instance".
https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/40685125-bug-get-scheduledtask-returns-null-for-value-of-m
#>
$MultipleInstances = [System.String] $settings.MultipleInstances
if ($MultipleInstances -eq $NULL) {
if ($task.settings.CimInstanceProperties.Item('MultipleInstances').Value -eq 3) {
$MultpleInstances = 'StopExisting'
}
}

$result = @{
TaskName = $task.TaskName
TaskPath = $task.TaskPath
Expand Down Expand Up @@ -1861,7 +1872,7 @@ function Get-CurrentResource
RestartOnIdle = $settings.IdleSettings.RestartOnIdle
DontStopOnIdleEnd = -not $settings.IdleSettings.StopOnIdleEnd
ExecutionTimeLimit = ConvertTo-TimeSpanStringFromScheduledTaskString -TimeSpan $settings.ExecutionTimeLimit
MultipleInstances = [System.String] $settings.MultipleInstances
MultipleInstances = $MultipleInstances
Priority = $settings.Priority
RestartCount = $settings.RestartCount
RestartInterval = ConvertTo-TimeSpanStringFromScheduledTaskString -TimeSpan $settings.RestartInterval
Expand Down

0 comments on commit a3f5a28

Please sign in to comment.