Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #306 #346

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 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,15 @@ 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 [System.Version]'5.0.0.0')
{
Disable-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath
}
else
{
Disable-ScheduledTaskEx -TaskName $TaskName -TaskPath $TaskPath
}

return
}
Expand Down Expand Up @@ -1635,7 +1643,7 @@ function ConvertTo-TimeSpanStringFromScheduledTaskString
.PARAMETER TaskPath
The path to the task to disable.
#>
function Disable-ScheduledTask
function Disable-ScheduledTaskEx
{
[CmdletBinding()]
param
Expand Down
21 changes: 19 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,15 @@ 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 [System.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 +1582,15 @@ 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 [System.Version]'5.0.0.0')
{
Assert-MockCalled Disable-ScheduledTask -Exactly -Times 1
}
else
{
Assert-MockCalled Register-ScheduledTask -Exactly -Times 1
}
}
}

Expand Down