@@ -165,7 +165,6 @@ function Get-TargetResource
165165 $action = $task.Actions | Select-Object - First 1
166166 $trigger = $task.Triggers | Select-Object - First 1
167167 $settings = $task.Settings
168- $repetition = $trigger.Repetition
169168 $returnScheduleType = " Unknown"
170169 $returnInveral = 0
171170
@@ -217,14 +216,17 @@ function Get-TargetResource
217216 {
218217 $Days = $matches.Days
219218 }
219+
220220 if ($repInterval -match ' (?<Hours>\d{0,2})H' )
221221 {
222222 $Hours = $matches.Hours
223223 }
224+
224225 if ($repInterval -match ' (?<Minutes>\d{0,2})M' )
225226 {
226227 $Minutes = $matches.Minutes
227228 }
229+
228230 if ($repInterval -match ' (?<Seconds>\d{0,2})S' )
229231 {
230232 $Seconds = $matches.Seconds
@@ -239,14 +241,17 @@ function Get-TargetResource
239241 {
240242 $Days = $matches.Days
241243 }
244+
242245 if ($repDuration -match ' (?<Hours>\d{0,2})H' )
243246 {
244247 $Hours = $matches.Hours
245248 }
249+
246250 if ($repDuration -match ' (?<Minutes>\d{0,2})M' )
247251 {
248252 $Minutes = $matches.Minutes
249253 }
254+
250255 if ($repDuration -match ' (?<Seconds>\d{0,2})S' )
251256 {
252257 $Seconds = $matches.Seconds
@@ -261,14 +266,17 @@ function Get-TargetResource
261266 {
262267 $Days = $matches.Days
263268 }
269+
264270 if ($resInterval -match ' (?<Hours>\d{0,2})H' )
265271 {
266272 $Hours = $matches.Hours
267273 }
274+
268275 if ($resInterval -match ' (?<Minutes>\d{0,2})M' )
269276 {
270277 $Minutes = $matches.Minutes
271278 }
279+
272280 if ($resInterval -match ' (?<Seconds>\d{0,2})S' )
273281 {
274282 $Seconds = $matches.Seconds
@@ -283,14 +291,17 @@ function Get-TargetResource
283291 {
284292 $Days = $matches.Days
285293 }
294+
286295 if ($exeLim -match ' (?<Hours>\d{0,2})H' )
287296 {
288297 $Hours = $matches.Hours
289298 }
299+
290300 if ($exeLim -match ' (?<Minutes>\d{0,2})M' )
291301 {
292302 $Minutes = $matches.Minutes
293303 }
304+
294305 if ($exeLim -match ' (?<Seconds>\d{0,2})S' )
295306 {
296307 $Seconds = $matches.Seconds
@@ -305,14 +316,17 @@ function Get-TargetResource
305316 {
306317 $Days = $matches.Days
307318 }
319+
308320 if ($idleDur -match ' (?<Hours>\d{0,2})H' )
309321 {
310322 $Hours = $matches.Hours
311323 }
324+
312325 if ($idleDur -match ' (?<Minutes>\d{0,2})M' )
313326 {
314327 $Minutes = $matches.Minutes
315328 }
329+
316330 if ($idleDur -match ' (?<Seconds>\d{0,2})S' )
317331 {
318332 $Seconds = $matches.Seconds
@@ -327,14 +341,17 @@ function Get-TargetResource
327341 {
328342 $Days = $matches.Days
329343 }
344+
330345 if ($idleWait -match ' (?<Hours>\d{0,2})H' )
331346 {
332347 $Hours = $matches.Hours
333348 }
349+
334350 if ($idleWait -match ' (?<Minutes>\d{0,2})M' )
335351 {
336352 $Minutes = $matches.Minutes
337353 }
354+
338355 if ($idleWait -match ' (?<Seconds>\d{0,2})S' )
339356 {
340357 $Seconds = $matches.Seconds
@@ -349,14 +366,17 @@ function Get-TargetResource
349366 {
350367 $Days = $matches.Days
351368 }
369+
352370 if ($rndDelay -match ' (?<Hours>\d{0,2})H' )
353371 {
354372 $Hours = $matches.Hours
355373 }
374+
356375 if ($rndDelay -match ' (?<Minutes>\d{0,2})M' )
357376 {
358377 $Minutes = $matches.Minutes
359378 }
379+
360380 if ($rndDelay -match ' (?<Seconds>\d{0,2})S' )
361381 {
362382 $Seconds = $matches.Seconds
@@ -376,7 +396,7 @@ function Get-TargetResource
376396
377397 $startAt = $trigger.StartBoundary
378398
379- if ($startAt )
399+ if ($startAt )
380400 {
381401 $startAt = [datetime ]$startAt
382402 }
@@ -410,7 +430,7 @@ function Get-TargetResource
410430 AllowStartIfOnBatteries = -not $settings.DisallowStartIfOnBatteries
411431 Hidden = $settings.Hidden
412432 RunOnlyIfIdle = $settings.RunOnlyIfIdle
413- IdleWaitTimeout = $idleWaitTimeout
433+ IdleWaitTimeout = $idleWaitTimeoutReturn
414434 NetworkName = $settings.NetworkSettings.Name
415435 DisallowStartOnRemoteAppSession = $settings.DisallowStartOnRemoteAppSession
416436 StartWhenAvailable = $settings.StartWhenAvailable
@@ -563,31 +583,31 @@ function Set-TargetResource
563583
564584 if ($Ensure -eq " Present" )
565585 {
566- if ($RepetitionDuration.TimeOfDay -lt $RepeatInterval.TimeOfDay )
586+ if ($RepetitionDuration.TimeOfDay -lt $RepeatInterval.TimeOfDay )
567587 {
568588 $exceptionObject = New-Object - TypeName System.ArgumentException - ArgumentList `
569589 (' Repetition duration {0} is less than repetition interval {1}. Please set RepeatInterval to a value lower or equal to RepetitionDuration' -f $RepetitionDuration.TimeOfDay , $RepeatInterval.TimeOfDay ),`
570590 ' RepeatInterval'
571591 throw $exceptionObject
572592 }
573593
574- if ($ScheduleType -eq ' Daily' -and $DaysInterval -eq 0 )
594+ if ($ScheduleType -eq ' Daily' -and $DaysInterval -eq 0 )
575595 {
576596 $exceptionObject = New-Object - TypeName System.ArgumentException - ArgumentList `
577597 (' Schedules of the type Daily must have a DaysInterval greater than 0 (value entered: {0})' -f $DaysInterval ),`
578598 ' DaysInterval'
579599 throw $exceptionObject
580600 }
581601
582- if ($ScheduleType -eq ' Weekly' -and $WeeksInterval -eq 0 )
602+ if ($ScheduleType -eq ' Weekly' -and $WeeksInterval -eq 0 )
583603 {
584604 $exceptionObject = New-Object - TypeName System.ArgumentException - ArgumentList `
585605 (' Schedules of the type Weekly must have a WeeksInterval greater than 0 (value entered: {0})' -f $WeeksInterval ),`
586606 ' WeeksInterval'
587607 throw $exceptionObject
588608 }
589609
590- if ($ScheduleType -eq ' Weekly' -and $DaysOfWeek.Count -eq 0 )
610+ if ($ScheduleType -eq ' Weekly' -and $DaysOfWeek.Count -eq 0 )
591611 {
592612 $exceptionObject = New-Object - TypeName System.ArgumentException - ArgumentList `
593613 ' Schedules of the type Weekly must have at least one weekday selected' , ' DaysOfWeek'
@@ -597,14 +617,17 @@ function Set-TargetResource
597617 $actionArgs = @ {
598618 Execute = $ActionExecutable
599619 }
620+
600621 if ($ActionArguments )
601622 {
602623 $actionArgs.Add (" Argument" , $ActionArguments )
603624 }
625+
604626 if ($ActionWorkingPath )
605627 {
606628 $actionArgs.Add (" WorkingDirectory" , $ActionWorkingPath )
607629 }
630+
608631 $action = New-ScheduledTaskAction @actionArgs
609632
610633 $settingArgs = @ {
@@ -631,14 +654,17 @@ function Set-TargetResource
631654 {
632655 $settingArgs.Add (' IdleDuration' , $IdleDuration.TimeOfDay )
633656 }
657+
634658 if ($IdleWaitTimeout.TimeOfDay -gt [timespan ]" 00:00:00" )
635659 {
636660 $settingArgs.Add (' IdleWaitTimeout' , $IdleWaitTimeout.TimeOfDay )
637661 }
662+
638663 if ($ExecutionTimeLimit.TimeOfDay -gt [timespan ]" 00:00:00" )
639664 {
640665 $settingArgs.Add (' ExecutionTimeLimit' , $ExecutionTimeLimit.TimeOfDay )
641666 }
667+
642668 if ($RestartInterval.TimeOfDay -gt [timespan ]" 00:00:00" )
643669 {
644670 $settingArgs.Add (' RestartInterval' , $RestartInterval.TimeOfDay )
@@ -723,7 +749,7 @@ function Set-TargetResource
723749 if ($currentValues.Ensure -eq " Present" )
724750 {
725751 Write-Verbose - Message (' Removing previous scheduled task' -f $TaskName )
726- Unregister-ScheduledTask - TaskName $TaskName - TaskPath $TaskPath
752+ $null = Unregister-ScheduledTask - TaskName $TaskName - TaskPath $TaskPath
727753 }
728754
729755 Write-Verbose - Message (' Creating new scheduled task' -f $TaskName )
@@ -750,7 +776,7 @@ function Set-TargetResource
750776 $registerArgs.Add (" User" , " NT AUTHORITY\SYSTEM" )
751777 }
752778
753- Register-ScheduledTask @registerArgs
779+ $null = Register-ScheduledTask @registerArgs
754780 }
755781
756782 if ($Ensure -eq " Absent" )
@@ -894,14 +920,14 @@ function Test-TargetResource
894920
895921 $CurrentValues = Get-TargetResource @PSBoundParameters
896922
897- if ($Ensure -eq ' Absent' -and $CurrentValues.Ensure -eq ' Absent' )
923+ if ($Ensure -eq ' Absent' -and $CurrentValues.Ensure -eq ' Absent' )
898924 {
899925 return $true
900926 }
927+
901928 if ($null -eq $CurrentValues )
902929 {
903930 return $false
904931 }
905- return Test-DscParameterState - CurrentValues $CurrentValues `
906- - DesiredValues $PSBoundParameters
932+ return Test-DscParameterState - CurrentValues $CurrentValues - DesiredValues $PSBoundParameters
907933}
0 commit comments