From 12941a969abcf218d926c6b38b58a6450ae0de1c Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Tue, 12 May 2020 20:04:27 -0500 Subject: [PATCH 01/14] Add 'StopExisting' to valid values for ScheduledTask MultipleInstances parameter - fixes Issue #333 --- CHANGELOG.md | 2 ++ .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 14 +++++++++--- .../DSC_ScheduledTask.schema.mof | Bin 8232 -> 16630 bytes .../DSCResources/DSC_ScheduledTask/README.md | 10 +++++++++ tests/Unit/DSC_ScheduledTask.Tests.ps1 | 21 +++++++++++++----- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2c771cb..2fe0fc92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Add "StopExisting" to valid values for ScheduledTask MultipleInstances parameter - Fixes [Issue #333](https://github.com/dsccommunity/ComputerManagementDsc/issues/333). + ## [8.2.0] - 2020-05-05 ### Changed diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 29e35b55..834e5baa 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -388,7 +388,7 @@ function Set-TargetResource $ExecutionTimeLimit = '08:00:00', [Parameter()] - [ValidateSet('IgnoreNew', 'Parallel', 'Queue')] + [ValidateSet('IgnoreNew', 'Parallel', 'Queue', 'StopExisting')] [System.String] $MultipleInstances = 'Queue', @@ -544,12 +544,16 @@ function Set-TargetResource WakeToRun = $WakeToRun RestartOnIdle = $RestartOnIdle DontStopOnIdleEnd = $DontStopOnIdleEnd - MultipleInstances = $MultipleInstances Priority = $Priority RestartCount = $RestartCount RunOnlyIfNetworkAvailable = $RunOnlyIfNetworkAvailable } + if ($MultipleInstances -ne 'StopExisting') + { + $settingParameters.Add('MultipleInstances', $MultipleInstances) + } + if ($IdleDuration -gt [System.TimeSpan] '00:00:00') { $settingParameters.Add('IdleDuration', $IdleDuration) @@ -577,6 +581,10 @@ function Set-TargetResource $setting = New-ScheduledTaskSettingsSet @settingParameters + if ($MultipleInstances -eq 'StopExisting') { + $setting.CimInstanceProperties.Item('MultipleInstances').Value = 3 + } + $scheduledTaskArguments += @{ Settings = $setting } @@ -1260,7 +1268,7 @@ function Test-TargetResource $ExecutionTimeLimit = '08:00:00', [Parameter()] - [ValidateSet('IgnoreNew', 'Parallel', 'Queue')] + [ValidateSet('IgnoreNew', 'Parallel', 'Queue', 'StopExisting')] [System.String] $MultipleInstances = 'Queue', diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof index 6583b6b9b4e4d8377f7637ba4dac0405f4edd3f5..0af3b470fee5535a411cff300dfa4d827f6e7a5d 100644 GIT binary patch literal 16630 zcmdU$>rY(Q6~)izO8p;3s8SrM!Eu^4QTw4HKpYfor)F&0Mp0@WCde35&rs?_`PbX7 z-&wOc=e~yNz@(`VFmvZT_E~%F=e_gqe|?=c(^-0vCi;1vj?-KHKTU7adAgU@(u1^~ zKD_>2OYf&&r&0P`qfRyUJRNE7yYyJ|U+XHNxw|L z(1_S^l(sZuGkrT}-YETEdp=2z(vHS`mRCDYPqp?$a$ZW7L%n9*AM)RkM)UJ^`cl{5 zWr?@)=))}cMVeM89A{}qI*ZRR(wZ+ddpf&5ok_nwlYgXLr+J<8bfR%_y1?KMEgAOn z*s1mhxtry<(0=TV1aEre7^M$%^+@Zz)JQO%N}~4Yx0?G#pD^-N5*!O7)_W^FZaT?V zGYM{cl0eSVP9y=WDd-Q$(T~w>r5VC?UD*6nza!xZKGyu{3{&jl)gWRU8C6@$c3$OB z8sXdrnfteu`Gw>;(TdpCc|*^f28%5`^(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bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof index 0af3b470fee5535a411cff300dfa4d827f6e7a5d..941b833bd4db84ba8ec675711a2facfb17c8b176 100644 GIT binary patch literal 8264 zcmcIpVUOE368)ZEK^O;Q18lrWu6Hfc4+m%MBu01FxwW%D-MfoVMnq^RoMb{_8wD6>kfzOq#8)qmZRi@I3ba$O+pPwW&PV~p;Us{jEYcaYUet9FEx>n9sMWUYk_C(;%r=QgNRP>cg z3Z0j{+GL@G!Suq;M2YJXb9XVhaAl#*T+mvy{EvQu+d`LW#}v6N7oxQF6ymu^)l61d z>Ei9e+ES#tP)TWv_4XPcFu{Q}$TZAa8{eFwv8MyGG%f9_uS(2p0kbvi+}e6CAr}q4 zs-!CAG&|%1SDlr$gEPAGXJeJGKuP(icVkZY)u!pO5ORZUO6shQC2zK z?v)pIJ~DJUGJ|_Kr}KN5$NjlkYJ5iIPuBUq0KK;>v6N;lDx(phlchFQsobf+o(ue> za_ydpsVY|ro=`Gbh@vt+DFQV9L0K{OS#hm$CCi~HRdFw~1K}&RPcN*o0b2C7BX0>= zZY9jiSFc~Z5WUN;xI)%o4V`kh*`wA7X;M+Unvv@mUwv7s39ZLbpsPK`4Gh7W1MVWX z@La+&J5c7jwMiC*HTqX2WKvjyHO>F4HOh6xgc1jT6;G9l=~`%$WK~LdWj?{n^e$XE zbE?GCUF*TC^SLUz;HC{}%w*=2SS>Vyky_=1fh+v%-e@wUF*iG4YHg;Z5#x>BJvN(s z@gEqn#~&XG<$zJ4H&htIq`qobo{HWyzM#wa2x(HNrM-WUC1JYGX~z$1V*lZ@8qove zs$!p+lcG|)Y@~ekVK^1uci2eF&Qv>!IHmJv5k2Kmu*WUeNQ77#gml73lW$EcopDSZ z5fk;GQuz^?F=f{1$pRXulJs1)wiG7~GEWym(6=f>hL!x>az4W)7Yl<)!w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--git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 834e5baa..6e3a09eb 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -581,7 +581,8 @@ function Set-TargetResource $setting = New-ScheduledTaskSettingsSet @settingParameters - if ($MultipleInstances -eq 'StopExisting') { + if ($MultipleInstances -eq 'StopExisting') + { $setting.CimInstanceProperties.Item('MultipleInstances').Value = 3 } From 830db9035c2341e5f172d598011f1a5cdf9588a3 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Wed, 10 Jun 2020 11:03:38 -0500 Subject: [PATCH 04/14] Issue-#333 Commit requested changes --- CHANGELOG.md | 2 +- .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 5 +++ tests/Unit/DSC_ScheduledTask.Tests.ps1 | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bdcb8ed..f6b8e3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed build failures caused by changes in `ModuleBuilder` module v1.7.0 by changing `CopyDirectories` to `CopyPaths` - Fixes [Issue #332](https://github.com/dsccommunity/ComputerManagementDsc/issues/332). -- StartedTask +- ScheduledTask - Add "StopExisting" to valid values for MultipleInstances parameter - Fixes [Issue #333](https://github.com/dsccommunity/ComputerManagementDsc/issues/333). ## [8.2.0] - 2020-05-05 diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index c3ff4d5d..95c4dffa 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -583,6 +583,11 @@ function Set-TargetResource $setting = New-ScheduledTaskSettingsSet @settingParameters + <# The following workaround is needed because the TASK_INSTANCES_STOP_EXISTING value of + https://docs.microsoft.com/en-us/windows/win32/taskschd/tasksettings-multipleinstances is missing + from the Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.MultipleInstancesEnum, + which is used for the other values of $MultipleInstances. (at least currently, as of June, 2020) + #> if ($MultipleInstances -eq 'StopExisting') { $setting.CimInstanceProperties.Item('MultipleInstances').Value = 3 diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index 6d451b97..be6eb36b 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -128,6 +128,38 @@ try } } + Context 'No scheduled task exists, but it should, with MultipleInstances = StopExisting' { + $testParameters = $getTargetResourceParameters + @{ + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'Once' + RepeatInterval = (New-TimeSpan -Minutes 15).ToString() + RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() + MultipleInstances = 'StopExisting' + Verbose = $true + } + + Mock -CommandName Get-ScheduledTask -MockWith { return $null } + + It 'Should return the correct values from Get-TargetResource for initial state' { + $result = Get-TargetResource @getTargetResourceParameters + $result.Ensure | Should -Be 'Absent' + } + + It 'Should return false from the test method' { + Test-TargetResource @testParameters | Should -BeFalse + } + + It 'Should create the scheduled task in the set method' { + Set-TargetResource @testParameters + } + + It 'Should return the correct values from Get-TargetResource for updated state' { + $result = Get-TargetResource @getTargetResourceParameters + $result.MultipleInstances | Should -Be $testParameters.MultipleInstances + } + + } + Context 'A scheduled task exists, but it should not' { $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' From a3f5a28000c23fd5b3a79e6d27126d532a0271bc Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Wed, 17 Jun 2020 00:21:27 -0500 Subject: [PATCH 05/14] Issue-#333 Workaround for Get-ScheduledTask bug --- .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 95c4dffa..4c2454aa 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -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 @@ -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 From abb57a1544f20a70334c01d0425e9bfd11fc25b0 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Wed, 17 Jun 2020 00:28:26 -0500 Subject: [PATCH 06/14] Issue-#333 Add new lines --- .../DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 4c2454aa..00a8c9e9 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1829,8 +1829,10 @@ function Get-CurrentResource 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) { + if ($MultipleInstances -eq $NULL) + { + if ($task.settings.CimInstanceProperties.Item('MultipleInstances').Value -eq 3) + { $MultpleInstances = 'StopExisting' } } From 20f0b89b7eeb452833224c4c86b71ac2d7fc5b55 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Wed, 17 Jun 2020 00:48:00 -0500 Subject: [PATCH 07/14] Issue-#333 Change to use IsNullOrEmpty --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 00a8c9e9..7a97deef 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1829,7 +1829,7 @@ function Get-CurrentResource 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 ([String]::IsNullOrEmpty($MultipleInstances)) { if ($task.settings.CimInstanceProperties.Item('MultipleInstances').Value -eq 3) { From 2ba9fffd9de7b63b6dd42b998ef0f2c2564bab0a Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Wed, 17 Jun 2020 01:46:46 -0500 Subject: [PATCH 08/14] Issue-#333 Add default values for settings in unit tests --- .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 2 +- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 99 ++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 7a97deef..7d1bde90 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1833,7 +1833,7 @@ function Get-CurrentResource { if ($task.settings.CimInstanceProperties.Item('MultipleInstances').Value -eq 3) { - $MultpleInstances = 'StopExisting' + $MultipleInstances = 'StopExisting' } } diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index be6eb36b..5df253e8 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -186,6 +186,10 @@ try CimClassName = 'MSFT_TaskTimeTrigger' } }) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = @{ UserId = 'SYSTEM' } @@ -348,6 +352,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -398,6 +406,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -443,6 +455,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -493,6 +509,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -537,6 +557,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -583,6 +607,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -629,6 +657,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'WrongUser' } @@ -681,6 +713,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'DEMO\RightUser' LogonType = 'Password' @@ -735,6 +771,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'DEMO\RightUser' RunLevel = 'Limited' @@ -789,6 +829,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -841,6 +885,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -893,8 +941,9 @@ try } } ) - Settings = [pscustomobject] @{ + Settings = [pscustomobject] @{ Enabled = $true + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -953,6 +1002,7 @@ try Settings = [pscustomobject] @{ Enabled = $true ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalSeconds + 60)S" + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1020,6 +1070,7 @@ try } ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.ExecutionTimeLimit).TotalMinutes)M" RestartInterval = "PT$([System.TimeSpan]::Parse($testParameters.RestartInterval).TotalMinutes)M" + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1070,6 +1121,7 @@ try ) Settings = [pscustomobject] @{ Enabled = $false + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1120,6 +1172,7 @@ try ) Settings = [pscustomobject] @{ Enabled = $false + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1174,6 +1227,7 @@ try ) Settings = [pscustomobject] @{ Enabled = $false + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1256,6 +1310,7 @@ try } ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.ExecutionTimeLimit).TotalMinutes)M" RestartInterval = "PT$([System.TimeSpan]::Parse($testParameters.RestartInterval).TotalMinutes)M" + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1321,6 +1376,7 @@ try } ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.ExecutionTimeLimit).TotalMinutes)M" RestartInterval = "PT$([System.TimeSpan]::Parse($testParameters.RestartInterval).TotalMinutes)M" + MultipleInstances = 'IgnoreNew' } Principal = [pscustomobject] @{ UserId = 'SYSTEM' @@ -1373,6 +1429,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -1424,6 +1484,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -1475,6 +1539,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'SYSTEM' } @@ -1760,6 +1828,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'NT AUTHORITY\' + $testParameters.BuiltInAccount LogonType = 'ServiceAccount' @@ -1830,6 +1902,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'gMSA$' } @@ -1877,6 +1953,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } Principal = [pscustomobject] @{ UserId = 'update_gMSA$' } @@ -1930,6 +2010,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } } } @@ -1960,6 +2044,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } } } @@ -2004,6 +2092,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } } } @@ -2034,6 +2126,10 @@ try } } ) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } } } @@ -2198,6 +2294,7 @@ try ) Settings = [pscustomobject] @{ Enabled = $testParameters.Enable + MultipleInstances = 'IgnoreNew' } } } From 995b3f4bac67e15fd451f5a6fce6f3da8d6f6771 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Wed, 17 Jun 2020 09:51:50 -0500 Subject: [PATCH 09/14] Issue-#333 Moved Get-TargetResource in same "It" block as Set-TargetResource --- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index 5df253e8..10fdf949 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -123,9 +123,12 @@ try Test-TargetResource @testParameters | Should -BeFalse } - It 'Should create the scheduled task in the set method' { + It 'Should create the scheduled task in the set method and return the correct values from Get-TargetResource' { Set-TargetResource @testParameters + $result = Get-TargetResource @getTargetResourceParameters + $result.Ensure | Should -Be 'Present' } + } Context 'No scheduled task exists, but it should, with MultipleInstances = StopExisting' { @@ -149,12 +152,10 @@ try Test-TargetResource @testParameters | Should -BeFalse } - It 'Should create the scheduled task in the set method' { + It 'Should create the scheduled task in the set method and return the correct values from Get-TargetResource' { Set-TargetResource @testParameters - } - - It 'Should return the correct values from Get-TargetResource for updated state' { $result = Get-TargetResource @getTargetResourceParameters + $result.Ensure | Should -Be 'Present' $result.MultipleInstances | Should -Be $testParameters.MultipleInstances } From b130b7082cdecd8e0cdac6c2737028fde0198877 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Thu, 18 Jun 2020 18:31:12 -0500 Subject: [PATCH 10/14] Issue-#333 Mock Register-ScheduledTask in unit tests --- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 70 ++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index 10fdf949..cf75063b 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -112,7 +112,33 @@ try Verbose = $true } - Mock -CommandName Get-ScheduledTask -MockWith { return $null } + $scheduledTask = $NULL + Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } + Mock -CommandName Register-ScheduledTask -MockWith { + $scheduledTask = @{ + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @(@{ + Execute = $testParameters.ActionExecutable + }) + Triggers = @(@{ + Repetition = @{ + Duration = "PT$([System.TimeSpan]::Parse($testParameters.RepetitionDuration).TotalMinutes)M" + Interval = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalMinutes)M" + } + CimClass = @{ + CimClassName = 'MSFT_TaskTimeTrigger' + } + }) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = 'IgnoreNew' + } + Principal = @{ + UserId = 'SYSTEM' + } + } + } It 'Should return the correct values from Get-TargetResource' { $result = Get-TargetResource @getTargetResourceParameters @@ -123,8 +149,12 @@ try Test-TargetResource @testParameters | Should -BeFalse } - It 'Should create the scheduled task in the set method and return the correct values from Get-TargetResource' { + It 'Should create the scheduled task in the set method' { Set-TargetResource @testParameters + Assert-MockCalled Register-ScheduledTask + } + + It 'Should return the correct values from Get-TargetResource' { $result = Get-TargetResource @getTargetResourceParameters $result.Ensure | Should -Be 'Present' } @@ -141,7 +171,33 @@ try Verbose = $true } - Mock -CommandName Get-ScheduledTask -MockWith { return $null } + $scheduledTask = $NULL + Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } + Mock -CommandName Register-ScheduledTask -MockWith { + $scheduledTask = @{ + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @(@{ + Execute = $testParameters.ActionExecutable + }) + Triggers = @(@{ + Repetition = @{ + Duration = "PT$([System.TimeSpan]::Parse($testParameters.RepetitionDuration).TotalMinutes)M" + Interval = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalMinutes)M" + } + CimClass = @{ + CimClassName = 'MSFT_TaskTimeTrigger' + } + }) + Settings = [pscustomobject] @{ + Enabled = $true + MultipleInstances = $testParameters.MultipleInstances + } + Principal = @{ + UserId = 'SYSTEM' + } + } + } It 'Should return the correct values from Get-TargetResource for initial state' { $result = Get-TargetResource @getTargetResourceParameters @@ -152,8 +208,14 @@ try Test-TargetResource @testParameters | Should -BeFalse } - It 'Should create the scheduled task in the set method and return the correct values from Get-TargetResource' { + It 'Should create the scheduled task in the set method' { Set-TargetResource @testParameters + Assert-MockCalled -CommandName Register-ScheduledTask -ParameterFilter { + $MultipleInstances -eq $testParameters.MultipleInstances + } + } + + It 'Should return the correct values from Get-TargetResource' { $result = Get-TargetResource @getTargetResourceParameters $result.Ensure | Should -Be 'Present' $result.MultipleInstances | Should -Be $testParameters.MultipleInstances From f0b1d7b6592cc43bb049a5bf591c9fd4e6b34354 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Thu, 18 Jun 2020 19:05:37 -0500 Subject: [PATCH 11/14] Issue-#333 Assert-MockCalled in unit tests --- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 99 ++++++++++---------------- 1 file changed, 37 insertions(+), 62 deletions(-) diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index cf75063b..fcafedbf 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -114,31 +114,7 @@ try $scheduledTask = $NULL Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } - Mock -CommandName Register-ScheduledTask -MockWith { - $scheduledTask = @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @(@{ - Execute = $testParameters.ActionExecutable - }) - Triggers = @(@{ - Repetition = @{ - Duration = "PT$([System.TimeSpan]::Parse($testParameters.RepetitionDuration).TotalMinutes)M" - Interval = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalMinutes)M" - } - CimClass = @{ - CimClassName = 'MSFT_TaskTimeTrigger' - } - }) - Settings = [pscustomobject] @{ - Enabled = $true - MultipleInstances = 'IgnoreNew' - } - Principal = @{ - UserId = 'SYSTEM' - } - } - } + Mock -CommandName Register-ScheduledTask It 'Should return the correct values from Get-TargetResource' { $result = Get-TargetResource @getTargetResourceParameters @@ -151,53 +127,25 @@ try It 'Should create the scheduled task in the set method' { Set-TargetResource @testParameters - Assert-MockCalled Register-ScheduledTask - } - - It 'Should return the correct values from Get-TargetResource' { - $result = Get-TargetResource @getTargetResourceParameters - $result.Ensure | Should -Be 'Present' + Assert-MockCalled Register-ScheduledTask -Exactly -Times 1 } } - Context 'No scheduled task exists, but it should, with MultipleInstances = StopExisting' { + Context 'No scheduled task exists, but it should, with MultipleInstances = Queue' { $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' ScheduleType = 'Once' RepeatInterval = (New-TimeSpan -Minutes 15).ToString() RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() - MultipleInstances = 'StopExisting' + MultipleInstances = 'Queue' Verbose = $true } $scheduledTask = $NULL Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } - Mock -CommandName Register-ScheduledTask -MockWith { - $scheduledTask = @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @(@{ - Execute = $testParameters.ActionExecutable - }) - Triggers = @(@{ - Repetition = @{ - Duration = "PT$([System.TimeSpan]::Parse($testParameters.RepetitionDuration).TotalMinutes)M" - Interval = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalMinutes)M" - } - CimClass = @{ - CimClassName = 'MSFT_TaskTimeTrigger' - } - }) - Settings = [pscustomobject] @{ - Enabled = $true - MultipleInstances = $testParameters.MultipleInstances - } - Principal = @{ - UserId = 'SYSTEM' - } - } - } + Mock -CommandName New-ScheduledTaskSettingsSet + Mock -CommandName Register-ScheduledTask It 'Should return the correct values from Get-TargetResource for initial state' { $result = Get-TargetResource @getTargetResourceParameters @@ -210,15 +158,42 @@ try It 'Should create the scheduled task in the set method' { Set-TargetResource @testParameters - Assert-MockCalled -CommandName Register-ScheduledTask -ParameterFilter { + Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 -ParameterFilter { $MultipleInstances -eq $testParameters.MultipleInstances } + Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 } - It 'Should return the correct values from Get-TargetResource' { + } + + Context 'No scheduled task exists, but it should, with MultipleInstances = StopExisting' { + $testParameters = $getTargetResourceParameters + @{ + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'Once' + RepeatInterval = (New-TimeSpan -Minutes 15).ToString() + RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() + MultipleInstances = 'StopExisting' + Verbose = $true + } + + $scheduledTask = $NULL + Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } + Mock -CommandName Register-ScheduledTask + + It 'Should return the correct values from Get-TargetResource for initial state' { $result = Get-TargetResource @getTargetResourceParameters - $result.Ensure | Should -Be 'Present' - $result.MultipleInstances | Should -Be $testParameters.MultipleInstances + $result.Ensure | Should -Be 'Absent' + } + + It 'Should return false from the test method' { + Test-TargetResource @testParameters | Should -BeFalse + } + + It 'Should create the scheduled task in the set method' { + Set-TargetResource @testParameters + Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 + # currently does not have ParameterFilter to ensure MultipleInstances is being set, like 'Queue' above + Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 } } From 49f0a100c124c5a341bc01316a93267b112e5d6c Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Fri, 19 Jun 2020 01:54:57 -0500 Subject: [PATCH 12/14] Issue-#333 Add mock function New-ScheduledTaskSettingsSet --- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 197 +++++++++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index fcafedbf..d59bc054 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -91,6 +91,135 @@ try ) } + # Function to allow mocking pipeline input + function New-ScheduledTaskSettingsSet + { + param + ( + [Parameter()] + [switch] + $DisallowDemandStart, + + [Parameter()] + [switch] + $DisallowHardTerminate, + + [Parameter()] + [Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.CompatibilityEnum] + [ValidateSet('At', 'V1', 'Vista', 'Win7', 'Win8')] + $Compatibility, + + [Parameter()] + [TimeSpan] + $DeleteExpiredTaskAfter, + + [Parameter()] + [switch] + $AllowStartIfOnBatteries, + + [Parameter()] + [switch] + $Disable, + + [Parameter()] + [switch] + $MaintenanceExclusive, + + [Parameter()] + [switch] + $Hidden, + + [Parameter()] + [switch] + $RunOnlyIfIdle, + + [Parameter()] + [TimeSpan] + $IdleWaitTimeout, + + [Parameter()] + [System.String] + $NetworkId, + + [Parameter()] + [System.String] + $NetworkName, + + [Parameter()] + [switch] + $DisallowStartOnRemoteAppSession, + + [Parameter()] + [TimeSpan] + $MaintenancePeriod, + + [Parameter()] + [TimeSpan] + $MaintenanceDeadline, + + [Parameter()] + [switch] + $StartWhenAvailable, + + [Parameter()] + [switch] + $DontStopIfGoingOnBatteries, + + [Parameter()] + [switch] + $WakeToRun, + + [Parameter()] + [TimeSpan] + $IdleDuration, + + [Parameter()] + [switch] + $RestartOnIdle, + + [Parameter()] + [switch] + $DontStopOnIdleEnd, + + [Parameter()] + [TimeSpan] + $ExecutionTimeLimit, + + [Parameter()] + [Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.MultipleInstancesEnum] + [ValidateSet('Parallel', 'Queue', 'IgnoreNew', 'StopExisting')] + $MultipleInstances, + + [Parameter()] + [int] + $Priority, + + [Parameter()] + [int] + $RestartCount, + + [Parameter()] + [TimeSpan] + $RestartInterval, + + [Parameter()] + [switch] + $RunOnlyIfNetworkAvailable, + + [Parameter()] + [CimSession[]] + $CimSession, + + [Parameter()] + [int] + $ThrottleLimit, + + [Parameter()] + [switch] + $AsJob + ) + } + Describe 'DSC_ScheduledTask' { BeforeAll { Mock -CommandName Register-ScheduledTask @@ -132,6 +261,40 @@ try } + Context 'No scheduled task exists, but it should, with MultipleInstances = Parallel' { + $testParameters = $getTargetResourceParameters + @{ + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'Once' + RepeatInterval = (New-TimeSpan -Minutes 15).ToString() + RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() + MultipleInstances = 'Parallel' + Verbose = $true + } + + $scheduledTask = $NULL + Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } + Mock -CommandName New-ScheduledTaskSettingsSet + Mock -CommandName Register-ScheduledTask + + It 'Should return the correct values from Get-TargetResource for initial state' { + $result = Get-TargetResource @getTargetResourceParameters + $result.Ensure | Should -Be 'Absent' + } + + It 'Should return false from the test method' { + Test-TargetResource @testParameters | Should -BeFalse + } + + It 'Should create the scheduled task in the set method' { + Set-TargetResource @testParameters + Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 -ParameterFilter { + $MultipleInstances -eq $testParameters.MultipleInstances + } + Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 + } + + } + Context 'No scheduled task exists, but it should, with MultipleInstances = Queue' { $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' @@ -166,6 +329,40 @@ try } + Context 'No scheduled task exists, but it should, with MultipleInstances = IgnoreNew' { + $testParameters = $getTargetResourceParameters + @{ + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'Once' + RepeatInterval = (New-TimeSpan -Minutes 15).ToString() + RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() + MultipleInstances = 'IgnoreNew' + Verbose = $true + } + + $scheduledTask = $NULL + Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } + Mock -CommandName New-ScheduledTaskSettingsSet + Mock -CommandName Register-ScheduledTask + + It 'Should return the correct values from Get-TargetResource for initial state' { + $result = Get-TargetResource @getTargetResourceParameters + $result.Ensure | Should -Be 'Absent' + } + + It 'Should return false from the test method' { + Test-TargetResource @testParameters | Should -BeFalse + } + + It 'Should create the scheduled task in the set method' { + Set-TargetResource @testParameters + Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 -ParameterFilter { + $MultipleInstances -eq $testParameters.MultipleInstances + } + Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 + } + + } + Context 'No scheduled task exists, but it should, with MultipleInstances = StopExisting' { $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' From ab454870a47ea1319b0de906cd680a6b4d0c20c3 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Fri, 19 Jun 2020 02:07:12 -0500 Subject: [PATCH 13/14] Issue-#333 Giving up, removing tests --- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 263 ------------------------- 1 file changed, 263 deletions(-) diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index d59bc054..49587433 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -91,135 +91,6 @@ try ) } - # Function to allow mocking pipeline input - function New-ScheduledTaskSettingsSet - { - param - ( - [Parameter()] - [switch] - $DisallowDemandStart, - - [Parameter()] - [switch] - $DisallowHardTerminate, - - [Parameter()] - [Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.CompatibilityEnum] - [ValidateSet('At', 'V1', 'Vista', 'Win7', 'Win8')] - $Compatibility, - - [Parameter()] - [TimeSpan] - $DeleteExpiredTaskAfter, - - [Parameter()] - [switch] - $AllowStartIfOnBatteries, - - [Parameter()] - [switch] - $Disable, - - [Parameter()] - [switch] - $MaintenanceExclusive, - - [Parameter()] - [switch] - $Hidden, - - [Parameter()] - [switch] - $RunOnlyIfIdle, - - [Parameter()] - [TimeSpan] - $IdleWaitTimeout, - - [Parameter()] - [System.String] - $NetworkId, - - [Parameter()] - [System.String] - $NetworkName, - - [Parameter()] - [switch] - $DisallowStartOnRemoteAppSession, - - [Parameter()] - [TimeSpan] - $MaintenancePeriod, - - [Parameter()] - [TimeSpan] - $MaintenanceDeadline, - - [Parameter()] - [switch] - $StartWhenAvailable, - - [Parameter()] - [switch] - $DontStopIfGoingOnBatteries, - - [Parameter()] - [switch] - $WakeToRun, - - [Parameter()] - [TimeSpan] - $IdleDuration, - - [Parameter()] - [switch] - $RestartOnIdle, - - [Parameter()] - [switch] - $DontStopOnIdleEnd, - - [Parameter()] - [TimeSpan] - $ExecutionTimeLimit, - - [Parameter()] - [Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.MultipleInstancesEnum] - [ValidateSet('Parallel', 'Queue', 'IgnoreNew', 'StopExisting')] - $MultipleInstances, - - [Parameter()] - [int] - $Priority, - - [Parameter()] - [int] - $RestartCount, - - [Parameter()] - [TimeSpan] - $RestartInterval, - - [Parameter()] - [switch] - $RunOnlyIfNetworkAvailable, - - [Parameter()] - [CimSession[]] - $CimSession, - - [Parameter()] - [int] - $ThrottleLimit, - - [Parameter()] - [switch] - $AsJob - ) - } - Describe 'DSC_ScheduledTask' { BeforeAll { Mock -CommandName Register-ScheduledTask @@ -261,140 +132,6 @@ try } - Context 'No scheduled task exists, but it should, with MultipleInstances = Parallel' { - $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'Once' - RepeatInterval = (New-TimeSpan -Minutes 15).ToString() - RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() - MultipleInstances = 'Parallel' - Verbose = $true - } - - $scheduledTask = $NULL - Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } - Mock -CommandName New-ScheduledTaskSettingsSet - Mock -CommandName Register-ScheduledTask - - It 'Should return the correct values from Get-TargetResource for initial state' { - $result = Get-TargetResource @getTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - } - - It 'Should return false from the test method' { - Test-TargetResource @testParameters | Should -BeFalse - } - - It 'Should create the scheduled task in the set method' { - Set-TargetResource @testParameters - Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 -ParameterFilter { - $MultipleInstances -eq $testParameters.MultipleInstances - } - Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 - } - - } - - Context 'No scheduled task exists, but it should, with MultipleInstances = Queue' { - $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'Once' - RepeatInterval = (New-TimeSpan -Minutes 15).ToString() - RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() - MultipleInstances = 'Queue' - Verbose = $true - } - - $scheduledTask = $NULL - Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } - Mock -CommandName New-ScheduledTaskSettingsSet - Mock -CommandName Register-ScheduledTask - - It 'Should return the correct values from Get-TargetResource for initial state' { - $result = Get-TargetResource @getTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - } - - It 'Should return false from the test method' { - Test-TargetResource @testParameters | Should -BeFalse - } - - It 'Should create the scheduled task in the set method' { - Set-TargetResource @testParameters - Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 -ParameterFilter { - $MultipleInstances -eq $testParameters.MultipleInstances - } - Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 - } - - } - - Context 'No scheduled task exists, but it should, with MultipleInstances = IgnoreNew' { - $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'Once' - RepeatInterval = (New-TimeSpan -Minutes 15).ToString() - RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() - MultipleInstances = 'IgnoreNew' - Verbose = $true - } - - $scheduledTask = $NULL - Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } - Mock -CommandName New-ScheduledTaskSettingsSet - Mock -CommandName Register-ScheduledTask - - It 'Should return the correct values from Get-TargetResource for initial state' { - $result = Get-TargetResource @getTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - } - - It 'Should return false from the test method' { - Test-TargetResource @testParameters | Should -BeFalse - } - - It 'Should create the scheduled task in the set method' { - Set-TargetResource @testParameters - Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 -ParameterFilter { - $MultipleInstances -eq $testParameters.MultipleInstances - } - Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 - } - - } - - Context 'No scheduled task exists, but it should, with MultipleInstances = StopExisting' { - $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'Once' - RepeatInterval = (New-TimeSpan -Minutes 15).ToString() - RepetitionDuration = (New-TimeSpan -Minutes 150).ToString() - MultipleInstances = 'StopExisting' - Verbose = $true - } - - $scheduledTask = $NULL - Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } - Mock -CommandName Register-ScheduledTask - - It 'Should return the correct values from Get-TargetResource for initial state' { - $result = Get-TargetResource @getTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - } - - It 'Should return false from the test method' { - Test-TargetResource @testParameters | Should -BeFalse - } - - It 'Should create the scheduled task in the set method' { - Set-TargetResource @testParameters - Assert-MockCalled -CommandName New-ScheduledTaskSettingsSet -Exactly -Times 1 - # currently does not have ParameterFilter to ensure MultipleInstances is being set, like 'Queue' above - Assert-MockCalled -CommandName Register-ScheduledTask -Exactly -Times 1 - } - - } - Context 'A scheduled task exists, but it should not' { $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' From 2deef34bf1e910335d4143f81ff5004325813548 Mon Sep 17 00:00:00 2001 From: Robert Simpson Date: Thu, 25 Jun 2020 21:57:25 -0500 Subject: [PATCH 14/14] Issue-#333 with requested changes --- CHANGELOG.md | 1 - source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 2 +- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 234d3277..935d3407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 by changing `CopyDirectories` to `CopyPaths` - Fixes [Issue #332](https://github.com/dsccommunity/ComputerManagementDsc/issues/332). - Pin `Pester` module to 4.10.1 because Pester 5.0 is missing code coverage - Fixes [Issue #336](https://github.com/dsccommunity/ComputerManagementDsc/issues/336). - - ScheduledTask - Add "StopExisting" to valid values for MultipleInstances parameter - Fixes [Issue #333](https://github.com/dsccommunity/ComputerManagementDsc/issues/333). diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 7d1bde90..79b366ee 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1829,7 +1829,7 @@ function Get-CurrentResource https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/40685125-bug-get-scheduledtask-returns-null-for-value-of-m #> $MultipleInstances = [System.String] $settings.MultipleInstances - if ([String]::IsNullOrEmpty($MultipleInstances)) + if ([System.String]::IsNullOrEmpty($MultipleInstances)) { if ($task.settings.CimInstanceProperties.Item('MultipleInstances').Value -eq 3) { diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index 49587433..a1247c30 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -112,7 +112,7 @@ try Verbose = $true } - $scheduledTask = $NULL + $scheduledTask = $null Mock -CommandName Get-ScheduledTask -MockWith { return $scheduledTask } Mock -CommandName Register-ScheduledTask