From 43b5bdf1f06c1e6aa9ef2c3c954850f6e6f79ad5 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 29 Jul 2020 23:26:56 +0200 Subject: [PATCH 1/4] Fixed issue #306 --- CHANGELOG.md | 6 ++++++ .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 11 +++++++++-- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 19 +++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0d7ec4f..28dfcceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ComputerManagementDsc - Automatically publish documentation to GitHub Wiki - Fixes [Issue #342](https://github.com/dsccommunity/ComputerManagementDsc/issues/342). +### Fixed + +- ScheduledTask + - Fixed issue with disabling scheduled tasks that have "Run whether user is + logged on or not" configured - Fixes [Issue #306](https://github.com/dsccommunity/ComputerManagementDsc/issues/306). + ## [8.3.0] - 2020-06-30 ### Changed diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 79b366ee..e2199abd 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -456,7 +456,14 @@ function Set-TargetResource -and -not $PSBoundParameters.ContainsKey('ActionExecutable')) { Write-Verbose -Message ($script:localizedData.DisablingExistingScheduledTask -f $TaskName, $TaskPath) - Disable-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath + if ($PSVersionTable.PSVersion -gt [Version]"5.0.0.0") + { + Disable-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath + } + else + { + Disable-ScheduledTaskCustom -TaskName $TaskName -TaskPath $TaskPath + } return } @@ -1635,7 +1642,7 @@ function ConvertTo-TimeSpanStringFromScheduledTaskString .PARAMETER TaskPath The path to the task to disable. #> -function Disable-ScheduledTask +function Disable-ScheduledTaskCustom { [CmdletBinding()] param diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index a1247c30..a31f4262 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -93,6 +93,7 @@ try Describe 'DSC_ScheduledTask' { BeforeAll { + Mock -CommandName Disable-ScheduledTask Mock -CommandName Register-ScheduledTask Mock -CommandName Set-ScheduledTask Mock -CommandName Unregister-ScheduledTask @@ -222,7 +223,14 @@ try It 'Should remove the scheduled task in the set method' { Set-TargetResource @testParameters - Assert-MockCalled Register-ScheduledTask -Exactly -Times 1 + if ($PSVersionTable.PSVersion -gt [Version]"5.0.0.0") + { + Assert-MockCalled Disable-ScheduledTask -Exactly -Times 1 + } + else + { + Assert-MockCalled Register-ScheduledTask -Exactly -Times 1 + } } } @@ -1573,7 +1581,14 @@ try It 'Should disable the scheduled task in the set method' { Set-TargetResource @testParameters - Assert-MockCalled Register-ScheduledTask -Exactly -Times 1 + if ($PSVersionTable.PSEdition -gt [Version]"5.0.0.0") + { + Assert-MockCalled Disable-ScheduledTask -Exactly -Times 1 + } + else + { + Assert-MockCalled Register-ScheduledTask -Exactly -Times 1 + } } } From 7a9879e7fcc3ace9db796f06460fb3c2403d93d4 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Thu, 30 Jul 2020 09:00:56 +0200 Subject: [PATCH 2/4] Updated function name as discussed with Daniel --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index e2199abd..1f5377f5 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -462,7 +462,7 @@ function Set-TargetResource } else { - Disable-ScheduledTaskCustom -TaskName $TaskName -TaskPath $TaskPath + Disable-ScheduledTaskEx -TaskName $TaskName -TaskPath $TaskPath } return @@ -1642,7 +1642,7 @@ function ConvertTo-TimeSpanStringFromScheduledTaskString .PARAMETER TaskPath The path to the task to disable. #> -function Disable-ScheduledTaskCustom +function Disable-ScheduledTaskEx { [CmdletBinding()] param From c239da9b3acc643973dc8be6925cb8d6b6d65e7b Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 4 Aug 2020 08:47:44 +0200 Subject: [PATCH 3/4] Incorporated review comments --- .../DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 3 ++- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 1f5377f5..02cf7ac0 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -456,7 +456,8 @@ function Set-TargetResource -and -not $PSBoundParameters.ContainsKey('ActionExecutable')) { Write-Verbose -Message ($script:localizedData.DisablingExistingScheduledTask -f $TaskName, $TaskPath) - if ($PSVersionTable.PSVersion -gt [Version]"5.0.0.0") + + if ($PSVersionTable.PSVersion -gt [System.Version]'5.0.0.0') { Disable-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath } diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index a31f4262..894c9203 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -223,7 +223,8 @@ try It 'Should remove the scheduled task in the set method' { Set-TargetResource @testParameters - if ($PSVersionTable.PSVersion -gt [Version]"5.0.0.0") + + if ($PSVersionTable.PSVersion -gt [System.Version]'5.0.0.0') { Assert-MockCalled Disable-ScheduledTask -Exactly -Times 1 } @@ -1581,7 +1582,8 @@ try It 'Should disable the scheduled task in the set method' { Set-TargetResource @testParameters - if ($PSVersionTable.PSEdition -gt [Version]"5.0.0.0") + + if ($PSVersionTable.PSEdition -gt [System.Version]'5.0.0.0') { Assert-MockCalled Disable-ScheduledTask -Exactly -Times 1 } From 19730f4e7ccbd9ef62855030be817e85a9ccf68c Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 4 Aug 2020 09:21:56 +0200 Subject: [PATCH 4/4] Pulled new changes from master --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28dfcceb..19fb21e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- ScheduledTask + - Fixed issue with disabling scheduled tasks that have "Run whether user is + logged on or not" configured - Fixes [Issue #306](https://github.com/dsccommunity/ComputerManagementDsc/issues/306). + ## [8.4.0] - 2020-08-03 ### Changed @@ -12,12 +18,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ComputerManagementDsc - Automatically publish documentation to GitHub Wiki - Fixes [Issue #342](https://github.com/dsccommunity/ComputerManagementDsc/issues/342). -### Fixed - -- ScheduledTask - - Fixed issue with disabling scheduled tasks that have "Run whether user is - logged on or not" configured - Fixes [Issue #306](https://github.com/dsccommunity/ComputerManagementDsc/issues/306). - ## [8.3.0] - 2020-06-30 ### Changed