Skip to content

Commit

Permalink
Fixed issue dsccommunity#306
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Jul 29, 2020
1 parent baa67fd commit 2e52e04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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
Expand Down
11 changes: 9 additions & 2 deletions source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -1635,7 +1642,7 @@ function ConvertTo-TimeSpanStringFromScheduledTaskString
.PARAMETER TaskPath
The path to the task to disable.
#>
function Disable-ScheduledTask
function Disable-ScheduledTaskCustom
{
[CmdletBinding()]
param
Expand Down
19 changes: 17 additions & 2 deletions tests/Unit/DSC_ScheduledTask.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 2e52e04

Please sign in to comment.