Skip to content

Commit

Permalink
Issue-dsccommunity#333 Commit requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-S committed Jun 10, 2020
1 parent 79ced86 commit 830db90
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions tests/Unit/DSC_ScheduledTask.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 830db90

Please sign in to comment.